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-1. Aligned esp-Based Stack Frame (Contd.)common:// See Note B belowpush edxsub esp, 20j = k;mov edx, [ebx + 8]mov [esp + 16], edxfoo(5);mov [esp], 5call foo.alignedreturn j;mov eax, [esp + 16]add esp, 20pop edxmov esp, ebxpop ebxret// NOTES:// (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, <strong>and</strong> adds// sufficient space to the stack so that the stack pointer is aligned to a 0 mod 16 boundary.D.1.2Aligned EDP-Based Stack FramesIn EDP-based frames, padding is also inserted immediately before the returnaddress. However, this frame is slightly unusual in that the return address may actuallyreside in two different places in the stack. This occurs whenever padding must beadded <strong>and</strong> exception h<strong>and</strong>ling is in effect for the function. Example D-2 shows thecode generated for this type of frame. The stack location of the return address isaligned 12 mod 16. This means that the value of EDP always satisfies the condition(EDP & 0x0f) == 0x08. In this case, the sum of the sizes of the return address, theprevious EDP, the exception h<strong>and</strong>ling record, the local variables, <strong>and</strong> the spill areamust be a multiple of 16 bytes. In addition, the parameter passing space must be amultiple of 16 bytes. For a call to a stdcall function, it is necessary for the caller toreserve some stack space if the size of the parameter block being pushed is not amultiple of 16.D-4

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

Saved successfully!

Ooh no, something went wrong!