Team LiB
Previous Section Next Section

Function Call

A function call in assembly language simply requires pushing the arguments to the function onto the stack in reverse order, and issuing a call instruction. After calling, the arguments are then popped back off of the stack. For example, consider the C code:

 printf("The number is %d", 88);

In assembly language, this would be rendered as:

 .section .data
 text_string:
 .ascii "The number is %d\0"
 .section .text
 pushl $88
 pushl $text_string
 call  printf
 popl  %eax
 popl  %eax      #%eax is just a dummy variable,
                 #nothing is actually being done
                 #with the value. You can also
                 #directly re-adjust %esp to the
                 #proper location.

Team LiB
Previous Section Next Section