Code sample:
int main(int argc, char *argv[]) {
return 0;
}
Compile with command: gcc -m32 -g -o main main.c
This is the assembly from objdump
:
080483db <main>:
int main(int argc, char *argv[]) {
80483db: 55 push ebp
80483dc: 89 e5 mov ebp,esp
return 0;
80483de: b8 00 00 00 00 mov eax,0x0
}
80483e3: 5d pop ebp
80483e4: c3 ret
80483e5: 66 90 xchg ax,ax
80483e7: 66 90 xchg ax,ax
80483e9: 66 90 xchg ax,ax
80483eb: 66 90 xchg ax,ax
80483ed: 66 90 xchg ax,ax
80483ef: 90 nop
Why does gcc add all the xchg ax, ax
and final nop
there? I notice that without adding -m32
, then those xchg ax, ax
instructions are removed, but nop still presents:
0000000004004d6 <main>:
int main(int argc, char *argv[]) {
4004d6: 55 push rbp
4004d7: 48 89 e5 mov rbp,rsp
4004da: 89 7d fc mov DWORD PTR [rbp-0x4],edi
4004dd: 48 89 75 f0 mov QWORD PTR [rbp-0x10],rsi
return 0;
4004e1: b8 00 00 00 00 mov eax,0x0
}
4004e6: 5d pop rbp
4004e7: c3 ret
4004e8: 0f 1f 84 00 00 00 00 nop DWORD PTR [rax+rax*1+0x0]
4004ef: 00