Stack Alignment
D
D-7
Example D-2 Aligned ebp-based Stack Frames
void _stdcall foo (int k)
{
int j;
foo:
push
ebx
mov
ebx, esp
sub
esp, 0x00000008
and
esp, 0xfffffff0
add
esp, 0x00000008
// esp is (8 mod 16)
after add
jmp
common
foo.aligned:
push
ebx
// esp is (8 mod 16)
after push
mov
ebx, esp
common:
push
ebp
// this slot will be
used for
// duplicate return pt
push ebp
// esp is (0 mod 16)
after push
// (rtn,ebx,ebp,ebp)
mov ebp, [ebx + 4]
// fetch return pointer
and store
mov [esp + 4], ebp
// relative to ebp
// (rtn,ebx,rtn,ebp)
mov
ebp, esp
// ebp is (0 mod 16)
sub
esp, 28
// esp is (4 mod 16)
//see
Note A
push
edx
// esp is (0 mod 16)
after push
continued
Summary of Contents for ARCHITECTURE IA-32
Page 1: ...IA 32 Intel Architecture Optimization Reference Manual Order Number 248966 013US April 2006...
Page 220: ...IA 32 Intel Architecture Optimization 3 40...
Page 434: ...IA 32 Intel Architecture Optimization 9 20...
Page 514: ...IA 32 Intel Architecture Optimization B 60...
Page 536: ...IA 32 Intel Architecture Optimization C 22...