In Assembly Language, Seventh Edition for x86 Processors by Kip Irvine, on page 211, it says under 5.53 The x86 Calling Convention which addresses the Microsoft x64 Calling Convention,
- When calling a subroutine, the stack pointer (
RSP
) must be aligned on a 16-byte boundary (a multiple of 16). TheCALL
instruction pushes an 8-byte return address on the stack, so the calling program must subtract 8 from the stack pointer, in addition to the 32 it already subtracts for the shadow space.
It goes on to show some assembly with a sub rsp, 8
right before the sub rsp, 20h
(for the 32-bytes of shadow space).
Is this a safe convention though? Is the Microsoft stack guaranteed to be aligned on 16-bytes before the CALL
instruction? Or, is the book wrong in assuming that the stack was
- aligned to 16-bytes prior to the
CALL
- had an 8-byte return addresses push onto the stack with the
CALL
- requires an additional
sub rsp, 8;
to get back to 16-byte alignment?