Stack 1. Push and pop operations push longthing pop longthing ;equivalent code ;equivalent code subl $4,%esp movl (%esp),longthing movl longthing,(%esp) addl $4,%esp 2. Call and return operations call function ret next: ... ;equivalent code using %eax ;equivalent code pop %eax subl $4,%esp jmp *eax lea next,(%esp) ;equivalent code using %eax jmp function movl %esp,%eax next: addl $4,%esp jmp *(%eax) [stafford@localhost stack]$ cat hello.c extern int printf (const char *, ...); main() { int i = 10, j = 20; printf("Hello world, &i = %08x, &j = %08x, sp-12 = %08x, sp-16 = %08x, sp-20 = %08x, sp-24 = %08x\n\ sp-28 = %08x, sp-32 = %08x, sp-36 = %08x, sp-40 = %08x, sp-44 = %08x, sp-48 = %08x\n\ sp-52 = %08x, sp-56 = %08x, sp-60 = %08x, sp-64 = %08x, sp-68 = %08x, sp-70 = %08x\n", &i, &j); } [stafford@localhost stack]$ gcc -S -O0 hello.c [stafford@localhost stack]$ gcc hello.s [stafford@localhost stack]$ more hello.s .file "hello.c" .section .rodata .align 4 .LC0: .ascii "Hello world, *i = %08x, " .string " *j = %08x, sp-12 = %08x, sp-16 = %08x, sp-20 = %08x, sp-24 = %08x\n sp-28 = %08x, sp-32 = %08x, sp-36 = %08x, sp-40 = %08x, sp-44 = %08x, sp-48 = %08x\n sp-52 = %08x, sp-56 = %08x, sp-60 = %08x, sp-64 = %08x, sp-68 = %08x, sp-70 = %08x\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 $36, %esp movl $10, -8(%ebp) movl $20, -12(%ebp) leal -12(%ebp), %eax movl %eax, 8(%esp) leal -8(%ebp), %eax movl %eax, 4(%esp) movl $.LC0, (%esp) call printf addl $36, %esp popl %ecx popl %ebp leal -4(%ecx), %esp ret .size main, .-main .ident "GCC: (GNU) 4.1.2 20070925 (Red Hat 4.1.2-27)" .section .note.GNU-stack,"",@progbits [stafford@localhost stack]$ ./a.out Hello world, &i = bfd91d50, &j = bfd91d4c, sp-12 = 08048419, sp-16 = 00667ce5, sp-20 = bfd91dfc, sp-24 = bfd91d68 sp-28 = 00000014, sp-32 = 0000000a, sp-36 = bfd91d70, sp-40 = bfd91dc8, sp-44 = 00651f70, sp-48 = 00638ca0 sp-52 = 08048400, sp-56 = bfd91dc8, sp-60 = 00651f70, sp-64 = 00000001, sp-68 = bfd91df4, sp-70 = bfd91dfc [stafford@localhost stack]$