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:
-
The first parameter is always in memory at 8(%ebp).
If there are more parameters, the second is at 12(%ebp), the third is at 16(%ebp), etc.
-
Remember the final value in %eax is the value returned.