
Untitled
By: a guest on
Aug 5th, 2012 | syntax:
None | size: 0.94 KB | hits: 12 | expires: Never
Understanding Assembly language output of a C program
#include <stdio.h>
static int i = 100;
/* Declard as extern since defined in hello.c */
extern int global;
int function(char *input)
{
printf("%sn", input);
return global;
};
.file "foo.c"
.data
.align 4
.type i, @object
.size i, 4
i:
.long 100
.text
.globl function
.type function, @function
function:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl 8(%ebp), %eax
movl %eax, (%esp)
call puts
movl global, %eax
leave
ret
.size function, .-function
.ident "GCC: (Debian 4.4.5-8) 4.4.5"
.section .note.GNU-stack,"",@progbits
pushl ptr //push char *ptr
call function
{
pushl ebp So stack contains:
ptr
ret-value
ebp
->with-esp-pointing-to-after-ebp
(ESP always points to the top of the stack but after the last pushed
element..?)
andl $-16, %esp
subl $32, %esp