previous | start | next

Practice: Tracing Function Execution (1)

What value would be returned by the function call f(5), f(-5), and f(0) if the IA32 assembly code for f is:

f:
        pushl   %ebp
        movl    %esp, %ebp
        cmpl    $0, 8(%ebp)
        jge     .L2
        movl    8(%ebp), %eax
        addl    $1, %eax
        jmp     .L3
.L2:
        cmpl    $0, 8(%ebp)
        jle     .L4
        movl    8(%ebp), %eax
        subl    $1, %eax
        jmp     .L3
.L4:
        movl    $0, %eax
.L3:
        popl    %ebp
        ret

Hints:



previous | start | next