previous | start | next

IA32 Assembly for: Function Calls (2)

int f(int x, int y)
{
  int m;

  m = max(x,y);

  return m * m;
}


f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp          ; make the stack 8 byte bigger
        movl    12(%ebp), %eax    ; parameter y is at 12(%ebp)
        movl    %eax, 4(%esp)     ; move y to 4 bytes below stack top
        movl    8(%ebp), %eax     ; parameter x is at 8(%ebp)
        movl    %eax, (%esp)      ; move x to the stack top
        call    max               ; call max, the return value will be in %eax
        leave                     ; restore the stack top to its old value
        imull   %eax, %eax        ; R[%eax] = R[%eax] * R[%eax]
        ret                       ; return value in %eax
   


previous | start | next