



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The memory layout of a spim (stanford pipeline intermediate language machine) system, focusing on the data segment, text segment, and stack segment. It also covers the process of calling procedures with various parameters and recursion, including the allocation and restoration of stack frames and registers.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Stack Segment Data SegmentText Segment
0x7fffff^ 0x
Layout of Memory
Parameter 5Parameter 6Parameter 7
... Saved RegistersLocal Variables Dynamic Variables
$fp $sp
Calling a Procedure: •^ Execute a
jal
instruction.
At the beginning of the called Procedure: •^ Register
$ra
needs to be saved to the location referenced by the stack
pointer • The appropriate display register must be saved into the following word ofthe stack frame. Save any other callee-saved registers in the frame. • Establish the new display pointer by copying
$sp
into the appropriate
display register. • Establish the stack frame by subtracting the frame size from the stackpointer. To return from a call: • Pop the stack frame by adding the frame size to
$sp
-^ Restore callee-saved registers, including the appropriate display register. •^ Return by jumping to the address in register
$ra
(it is also at the location
now referenced by
$sp
Calling a Procedure: •^ Pass the parameters. By convention, the first four parameters are passed inregisters
$a0-$a
. The remaining arguments are pushed on the stack -^ Set up the static chain register (necessary if the procedure is nested withinanother dynamically allocated scope). •^ Save the caller-saved registers,
$t0-$t
, if they contain live values at the call
site. • Execute a
jal
instruction.
At the beginning of the called Procedure: •^ Save the callee-saved registers in the frame. Register
$fp
must be saved
since it is being used to reference variables in the calling frame. Register $ra
needs to be saved in order to allow the routine itself to make calls. Any of the registers
$s0-$s
that are used by the callee need to be saved.
-^ Establish the stack frame by subtracting the frame size from the stackpointer. Establish the frame pointer
$fp
by adding the stack frame size to
$sp