previous | start | next

Compiler Code for call to sum

Assuming local variables have offsets in main's stack frame like this:

int a; -16(%ebp) int b; -12(%ebp) int ans; -8(%ebp) int n; -4(%ebp)

We may expect this assembler code for the ans = sum(a,b); C statement if

    subl  $16,%esp      ;  allocate space for main local variables
    ...                 ;  code before call to sum not shown
    pushl -12(%ebp)     ;  push b       
    pushl -16(%ebp)     ;  push a       
    call  sum           ;  sum(a,b)
    movl  %eax,-8(%ebp) ;  ans = return value of sum(a,b)


previous | start | next