13.07.2015 Views

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

STACK ALIGNMENTExample D-2. Aligned ebp-based Stack Framesvoid _stdcall foo (int k){int j;foo:push ebxmov ebx, espsub esp, 0x00000008<strong>and</strong> esp, 0xfffffff0add esp, 0x00000008 // esp is (8 mod 16) after addjmp commonfoo.aligned:push ebx // esp is (8 mod 16) after pushmov ebx, espcommon:push ebp // this slot will be used for// duplicate return ptpush ebp// esp is (0 mod 16) after push// (rtn,ebx,ebp,ebp)mov ebp, [ebx + 4] // fetch return pointer <strong>and</strong> storemov [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 belowpush edx // esp is (0 mod 16) after push// goal is to make esp <strong>and</strong> ebp// (0 mod 16) herej = k;mov edx, [ebx + 8] // k is (0 mod 16) if caller// aligned its stackmov [ebp - 16], edx // J is (0 mod 16)foo(5);add esp, -4 // normal call sequence to// unaligned entrymov [esp],5call foo// for stdcall, callee// cleans up stackD-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!