






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







2
Pass parameters on stack Transfer control to start of function Remember return address Where? Save register values Allocate space for local variables on stack
Pass return value (through stack) Restore register values Clean up stack Transfer control back to return address On a stack (in main memory) on stack from the stack
4
0x 0x 0x 0x R29 0x PushByte: SUBI R29, R29, 1 SB 0(R29), Rs PopByte: LB Rd, 0(R29) ADDI R29, R29, 1 Example: Growing down (into lower addresses) in memory R29 pointing at current top of stack element
5
void A() { … B(5); … } void B (int x) { int a, b; … return(); } ADDI R1, R0, 5 ADDI R29, R29, 4 SW 0(R29), R B:
5 (int x) Function Call/Return Stack JAL B
7
void A() { … B(5); … } void B (int x) { int a, b; … return(); } ADDI R1, R0, 5 ADDI R29, R29, 4 SW 0(R29), R JAL B ADDI R29, R29, 4 SW 0(R29), R B:
5 (int x) Return address Local int a Local int b ADDI R29, R29, 8 … SUBI R29, R29, 16 LW R31, 8(R29) JR R Function Call/Return Stack
8
text data stack heap Use of memory addresses
10