Example d-1 – Intel ARCHITECTURE IA-32 User Manual

Page 541

Advertising
background image

Stack Alignment

D

D-5

Example D-1 Aligned esp-Based Stack Frames

void _cdecl foo (int k)

{

int j;

foo: // See Note A

push ebx

mov ebx, esp

sub esp, 0x00000008

and esp, 0xfffffff0

add esp, 0x00000008

jmp common

foo.aligned:

push ebx

mov ebx, esp

common: // See Note B

push edx

sub esp, 20

j = k;

mov edx, [ebx + 8]

mov [esp + 16], edx

foo(5);

mov [esp], 5

call foo.aligned

return j;

mov eax, [esp + 16]

add esp, 20

pop edx

mov esp, ebx

pop ebx

ret

Advertising