07-24-2023, 07:45 AM
So I have this c code:
#include <stdio.h>
int main(void)
{
int a;
int b;
int c;
a=b=c=5;
printf("Hi%d%d%dHi",a,b,c);
}
I compiled it on ubuntu with:
gcc program.c -o program -ggdb -m32 -O2
And then disassembled it with:
objdump -M intel program -d
And in main printf() gets called like this:
mov DWORD PTR [esp+0x10],0x5
mov DWORD PTR [esp+0xc],0x5
mov DWORD PTR [esp+0x8],0x5
mov DWORD PTR [esp+0x4],0x8048500
mov DWORD PTR [esp],0x1
call 8048330 <__printf_chk@plt>
What I am wondering right now is what this means:
mov DWORD PTR [esp],0x1
I know what the first 4 mov instructions are for, but I just can't figure out why a '1' gets pushed onto the stack. Also this mov only occurs when optimization is turned on. Any ideas?
#include <stdio.h>
int main(void)
{
int a;
int b;
int c;
a=b=c=5;
printf("Hi%d%d%dHi",a,b,c);
}
I compiled it on ubuntu with:
gcc program.c -o program -ggdb -m32 -O2
And then disassembled it with:
objdump -M intel program -d
And in main printf() gets called like this:
mov DWORD PTR [esp+0x10],0x5
mov DWORD PTR [esp+0xc],0x5
mov DWORD PTR [esp+0x8],0x5
mov DWORD PTR [esp+0x4],0x8048500
mov DWORD PTR [esp],0x1
call 8048330 <__printf_chk@plt>
What I am wondering right now is what this means:
mov DWORD PTR [esp],0x1
I know what the first 4 mov instructions are for, but I just can't figure out why a '1' gets pushed onto the stack. Also this mov only occurs when optimization is turned on. Any ideas?