spring elec 5200 0016200 001 lecture 4 22 recursive

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Nested Programs The following convention is understood and used by all calling (caller) and called (callee) programs. Preserved Not preserved Saved reg. $s0 - $s7 Stack pointer reg. $sp Return addr. Reg. $ra Stack above the stack pointer Temp. reg. $t0 - $t9 Argument reg. $a0 - $a3 Return value reg. $v0 - $v1 Stack below the stack pointer Spring 2014, Feb 10 . . . Spring ELEC 5200-001/6200-001 Lecture 4 23 When Calee becomes a Caller Saving and restoring of saved and Saving temporary registers is done same as described before. described May reuse argument registers ($a0 - $a3); May they are saved and restored as necessary. they Must reuse $ra; its content is saved in Must memory and restored on return. memory Spring 2014, Feb 10 . . . Spring ELEC 5200-001/6200-001 Lecture 4 24 Example: Program→Callee A→Calee B Main program . . addi $a0, $zero, 3 jal A . . Spring 2014, Feb 10 . . . Spring Procedure A . . addi $sp, $sp, -8 sw $ra, 4($sp) sw $a0, 0($sp) addi $a0, $zero, 7 jal B lw $a0, 0($sp) lw $ra, 4($sp) addi $sp, $sp, 8 . . jr $ra ELEC 5200-001/6200-001 Lecture 4 Procedure B . . . jr $ra 25 E...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online