Section Exercises
True or False:
Multiple Choice
Why is it or is it not the stack misaligned in the following cases?
The stack is misaligned.
It can be seen in the code associated with this answer option that we first reserve 16 bytes of space on the stack for two variables by subtracting 16. Before calling foo, rdi is pushed on the stack, meaning that we add another 8 bytes on the stack. As a result, there were 24 bytes added to the stack instead of a number of bytes equal to a multiple of 16.
The stack is aligned.
Although we only need space on the stack for a value, by subtracting only 8 bytes, the calling convention is broken. To make the stack 16 aligned, another 8 bytes are subtracted before foo is called.
The stack is aligned.
By pushing 4 on the stack (8 bytes) and then subtracting 16 and then pushing rdi (8 bytes), we reserve 32 bytes on the stack, which is a multiple of 16.
The stack is misaligned.
In the above code example, we observe that 16 bytes are allocated on the stack and that 4 and rsi are pushed on the stack, meaning that we reserve 32 bytes on the stack. By popping the top of the stack in rdi, we reduce the stack size by 8 bytes, resulting in only 24 bytes being reserved on the stack.
Last updated