im just interested in the following example
#include<stdio.h>
int test();
int test(){
return ;
}
int main(){
printf("%u\n",test());
return 0;
}
i compiled it using 'gcc -Wall -o semicolon semicolon.c' to create an executable file and 'gcc -Wall -S semicolon.c' to get the assembler code, which:
.file "semicolon.c"
.text
.globl test
.type test, @function
test:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
leave
ret
.size test, .-test
.section .rodata
.LC0:
.string "%u\n"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $20, %esp
call test
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
addl $20, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3"
.section .note.GNU-stack,"",@progbits
since im is not such an assembler pro, I only know that printf prints what is in eax but I don’t fully understand what “movl% eax, 4 (% esp)” means, I assume filling eax before calling the test but what then is the value? what does 4 (% esp) mean and what does esp mean?
if I uncomment the lines in test () printf prints 6 - which is written in eax ^^
source
share