Memory Layout and Stack Frame Allocation in SPIM, Study notes of Computer Science

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

Pre 2010

Uploaded on 08/05/2009

koofers-user-owy-1
koofers-user-owy-1 🇺🇸

3

(1)

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
SPIM Memory Layout
Data Segment
Text Segment
Stack Segment
0x400000
0x7fffff
Layout of Memory
pf3
pf4
pf5

Partial preview of the text

Download Memory Layout and Stack Frame Allocation in SPIM and more Study notes Computer Science in PDF only on Docsity!

SPIM Memory Layout

Stack Segment Data SegmentText Segment

0x7fffff^ 0x

Layout of Memory

Layout of a Stack Frame

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

Procedures: No Parameters, with Recursion

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

Procedures: Parameters and Recursion with Chains