Hi, I'm just wondering about local variables.
I've written the following code:
displayMessage:
push ebp
mov ebp, esp
and esp, -16
sub esp, 4
mov dword [esp], 3
push dword dword [esp]
push message
call _printf
add esp, 4
mov esp, ebp
pop ebp
ret
And it works. But when I've looked at the output from C compilers, it seems to align the stack to 16 bytes.
So the above would be:
displayMessage:
push ebp
mov ebp, esp
and esp, -16
sub esp, 16
mov dword [esp+12], 3
push dword dword [esp+12]
push message
call _printf
add esp, 16
mov esp, ebp
pop ebp
ret
Should I be aligning the stack to 16 bytes like this or is it just something C does? Will my code run faster when my stack pointer is aligned to 16 bytes?