Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 0.94 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Understanding Assembly language output of a C program
  2. #include <stdio.h>
  3.  
  4.  static int i = 100;
  5.  
  6.  /* Declard as extern since defined in hello.c */
  7.  extern int global;
  8.  
  9.  int function(char *input)
  10.  {
  11.   printf("%sn", input);
  12.   return global;
  13.  };
  14.  
  15.     .file   "foo.c"
  16.     .data
  17.     .align 4
  18.     .type   i, @object
  19.     .size   i, 4
  20. i:
  21.     .long   100
  22.     .text
  23. .globl function
  24.     .type   function, @function
  25. function:
  26.     pushl   %ebp
  27.     movl    %esp, %ebp
  28.     subl    $24, %esp
  29.     movl    8(%ebp), %eax
  30.     movl    %eax, (%esp)
  31.     call    puts
  32.     movl    global, %eax
  33.     leave
  34.     ret
  35.     .size   function, .-function
  36.     .ident  "GCC: (Debian 4.4.5-8) 4.4.5"
  37.     .section    .note.GNU-stack,"",@progbits
  38.        
  39. pushl ptr //push char *ptr
  40. call function
  41. {
  42. pushl ebp So stack contains:
  43. ptr
  44. ret-value
  45. ebp
  46. ->with-esp-pointing-to-after-ebp
  47. (ESP always points to the top of the stack but after the last pushed  
  48. element..?)
  49.        
  50. andl $-16, %esp
  51. subl $32, %esp