max: <max(int x, int y)>:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl 8(%ebp), %eax reg1 = x
cmpl 12(%ebp), %eax [compare y, reg1]
jge .L2 if (reg1 >= y) goto L2
movl 12(%ebp), %eax reg1 = y
movl %eax, -4(%ebp) maxVal = reg1
jmp .L4 goto L4
.L2: L2:
movl 8(%ebp), %eax reg1 = x
movl %eax, -4(%ebp) maxVal = reg1
.L4: L4:
movl -4(%ebp), %eax reg1 = maxVal
leave
ret return
Notes:
-
At L2 memory location x is moved to register %eax (it's already there). Then register %eax value is moved to memory location maxVal. The register is used as a temporary only because the movl instruction can't have both operands be in memory.
-
At L4, the value in maxVal is moved back to register %eax. This time register %eax is not used as a temporary location, but because the return value of a function is always expected to be in register %eax.