Intel ARCHITECTURE IA-32 User Manual

Page 544

Advertising
background image

Stack Alignment

D

D-8

// the goal is to make

esp and ebp

// (0 mod 16) here

j = k;

mov

edx, [ebx + 8]

// k is (0 mod 16) if

caller aligned

// its stack

mov

[ebp - 16], edx

// J is (0 mod 16)

foo(5);

add

esp, -4

// normal call sequence

to

//

unaligned

entry

mov [esp],5

call foo

// for stdcall, callee

// cleans up stack

foo.aligned(5);

add esp,-16

// aligned entry, this

should

// be a multiple of 16

mov [esp],5

call foo.aligned

add esp,12

// see Note B

return j;

mov eax,[ebp-16]

pop edx

mov esp,ebp

pop ebp

mov esp,ebx

pop ebx

ret 4

}

Example D-2 Aligned ebp-based Stack Frames (continued)

Advertising