027outlinel27 w10M PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CS 354 - Machine Organization

Monday, November 7, 2016

Project p4 (6%) due 10 pm Sunday, November 20th


Homework hw6 (1.5%) due 10 pm Wednesday, November 9th
Last Time
Jumps Instructions
Encoding Targets
Converting Loops
Today
Condititonal Moves (from last time)
Call Stack Review
Stack Frames
Transferring Control
Next Time
Read: B&O 3.7
Procedures

Copyright 2016 Jim Skrentny

CS 354 (F16): L27 - 1

Programmers Perspective of the Call Stack

Trace the following code using a stack trace:


int inc(int index, int size) {
int incindex = index + 1;
if (incindex == size) return 0;
return incindex;
}
int dequeue(int *queue, int *front,
int rear, int *numitems, int size) {
if (*numitem == 0) return -1;
int dqitem = queue[*front];
*front = inc(*front, size);
*numitems -= 1;
return dqitem;
}
int main(void) {
int queue[5] = {1,2,3};
int front = 0;
int rear = 3;
int numitems = 3;
int qitem = dequeue(queue, &front, rear,
&numitems, 5);
...

What does the compiler need to do to make function calls work?

Copyright 2016 Jim Skrentny

CS 354 (F16): L27 - 2

The Stack and Stack Frames


Remember the Call Stack:
Stack bottom
Stack

Earlier Stack Frames

Heap
Uninit Data
Init Data
Code

Callers Stack Frame

Ox00000000

Callees Stack Frame

Stack Frame

Parameter Passing

Local Variables

Copyright 2016 Jim Skrentny

CS 354 (F16): L27 - 3

Tansferring Control

Instructions
call Label
call *Operand
leave
ret

call
1.
2.

leave
1.
2.

ret
1.
2.

Copyright 2016 Jim Skrentny

CS 354 (F16): L27 - 4

You might also like