Subroutines and Control Abstraction-1
Subroutines and Control Abstraction-1
Control Abstraction
• Allocation strategies
– Static
• Code
• Globals
• Own variables
• Explicit constants (including strings, sets, other
aggregates)
• Small scalars may be stored in the instructions
themselves
• Caller
– saves into the temporaries and locals area any caller-saves
registers whose values will be needed after the call
– puts up to 4 small arguments into registers $4-$7 (a0-a3)
• it depends on the types of the parameters and the order in which
they appear in the argument list
– puts the rest of the arguments into the arg build area at the
top of the stack frame
– does jal (jump and link), which puts return address into
register ra and branches
– PC+4 in $ra
• In prolog, Callee
– subtracts frame size from sp
– saves callee-saves registers used anywhere inside callee
– copies sp to fp
• In epilog, Callee
– puts return value into registers (mem if large)
– copies fp into sp
– restores saved registers using sp as base
– adds to sp to deallocate frame
– does jra -returns control to the caller, It copies the contents
of $ra into the PC.