Aligned ebp-based stack frames – Intel ARCHITECTURE IA-32 User Manual

Page 542

Advertising
background image

Stack Alignment

D

D-6

Aligned ebp-Based Stack Frames

In

ebp

-based frames, padding is also inserted immediately before the

return address. However, this frame is slightly unusual in that the return
address may actually reside in two different places in the stack. This
occurs whenever padding must be added and exception handling is in
effect for the function. Example D-2 shows the code generated for this
type of frame. The stack location of the return address is aligned 12 mod
16. This means that the value of

ebp

always satisfies the condition

(ebp

& 0x0f) == 0x08

. In this case, the sum of the sizes of the return

address, the previous

ebp

, the exception handling record, the local

variables, and the spill area must be a multiple of 16 bytes. In addition,
the parameter passing space must be a multiple of 16 bytes. For a call to
a

stdcall

function, it is necessary for the caller to reserve some stack

space if the size of the parameter block being pushed is not a multiple
of 16.

NOTE.

A. Aligned entry points assume that parameter

block beginnings are aligned. This places the stack
pointer at a 12 mod 16 boundary, as the return pointer
has been pushed. Thus, the unaligned entry point must
force the stack pointer to this boundary.
B. The code at the common label assumes the
stack is at an 8 mod 16 boundary, and adds sufficient
space to the stack so that the stack pointer is aligned to
a 0 mod 16 boundary.

Advertising