Bryand and O'Hallaron Chapter 3 Section 3.6.4 Translating if Statements ironman:~/bando/chap3/sec6>more sec364.c int absdiff(int x, int y) { if (x < y) return y-x; else return x - y; } ironman:~/bando/chap3/sec6>gcc -S -O2 sec364.c ironman:~/bando/chap3/sec6>more sec364.s ... absdiff: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx # x movl 12(%ebp), %eax # y cmpl %eax, %edx jge .L2 # jump if %edx >= %eax popl %ebp subl %edx, %eax ret .p2align 4,,7 .L2: popl %ebp subl %eax, %edx movl %edx, %eax ret Bryant & O'Halloran Compiler ... absdiff: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx # x movl 12(%ebp), %eax # y cmpl %eax, %edx jl .L3 # jump if %edx < %eax subl %eax, %edx # x - y movl %edx, %eax jmp .L5 .L3: subl %edx, %eax # y - x .L5 popl %ebp ret int absdiff(int x, int y) { int rval; if (x < y) goto less; rval = y-x; goto done; less: rval = y - x; done: return rval; }