This is my C program using puts() :
#include <stdio.h> int main(void){ puts("testing"); }
After using gcc -S -o sample.s sample.c to compile it into Assembly, this is what I got:
.file "sample.c" .section .rodata .LC0: .string "testing" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $16, %esp movl $.LC0, (%esp) call puts leave ret .size main, .-main .ident "GCC: (GNU) 4.4.5 20110214 (Red Hat 4.4.5-6)" .section .note.GNU-stack,"",@progbits
I did the same, this time I used printf() instead of puts, and this is what I got:
.file "sample.c" .section .rodata .LC0: .string "testing" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $16, %esp movl $.LC0, %eax //this is the difference movl %eax, (%esp) call printf leave ret .size main, .-main .ident "GCC: (GNU) 4.4.5 20110214 (Red Hat 4.4.5-6)" .section .note.GNU-stack,"",@progbits
Here's what I don't understand, printf() function mov $.LC0 to %eax , then mov %eax to (%esp) , and function puts() mov %.LC0 directly on (%esp) . I do not know why this is.
c assembly gcc
the anh tin
source share