Topic V0D
Recursive Functions
1
, Non-Leaf Klay call other functions
Procedures
Procedures that call other procedures
• For nested calls, caller needs to:
• Save on the stack:
• ra
• callee-saved registers
• Restore values from the stack before returning
2
, Calling
Itself
factorial
function int fact(int n){
if (n < 1)
return 1;
else
return (n * fact(n –
1));
}
3
, Step-by-step creation of the
assembly code for fact
4
Recursive Functions
1
, Non-Leaf Klay call other functions
Procedures
Procedures that call other procedures
• For nested calls, caller needs to:
• Save on the stack:
• ra
• callee-saved registers
• Restore values from the stack before returning
2
, Calling
Itself
factorial
function int fact(int n){
if (n < 1)
return 1;
else
return (n * fact(n –
1));
}
3
, Step-by-step creation of the
assembly code for fact
4