Everything
9.1.5 Stack frame

(1)

Value to be set to stack pointer

An address which is a multiple of 2 is set to the stack pointer (SP).

(2)

Allocation and deallocation of stack frame

The stack pointer always points to the lowest address of the stack frame. Therefore, values stored in areas with smaller addresses than the SP address are not guaranteed.

A stack area allocated by the caller function when the function is called is deallocated by the caller function on returning from the function call. Accordingly, the SP indicates the return address storage area at the entrance and exit of the callee function.

(3)

Structure of the stack frame

Below is shown the stack frame of functions f and g from the perspective of function f (Callee function), when function f is called by function g (Caller function).

Figure 9.1

Contents of Stack Frame

 

Below is the area that function f can reference and set.

(a)

Area for allocating parameters received by function f

This is an area for setting parameters that are not allocated to registers. The data set in this area is aligned to the 2-byte boundary. When all parameters are allocated to registers, the size of this area becomes 0.

(b)

Area for storing the return address

This is an area for allocating the return address. The size of this area is fixed to 4 bytes, and the address is set as a far address.

The value of the upper one byte of the 4 bytes is undefined.

(c)

Area for storing local variables of function f

This is a stack area used by function f to store local variables.

(d)

Area for allocating arguments to be passed to the function called from function f

This is an area for setting arguments to be allocated to the stack when function f calls another function. If all arguments required for the function call are allocated to registers, the size of this area becomes 0.