CS485G Spring 2015 19
1 int absdiff(int x, int y)
2 {
3 int result;
4 if (x > y) {
5 result = x-y;
6 } else {
7 result = y-x;
8 }
9 return result;
10 }
absdiff:
pushl %ebp # save base pointer
movl %esp,%ebp # new base pointer
movl 8(%ebp), %edx # d = x
movl 12(%ebp), %eax # a = y
cmpl %eax, %edx # x <> y ?
jle .L6 # jump if x <= y
subl %eax, %edx # x = x - y
movl %edx, %eax # a = x - y
jmp .L7 # jump
.L6:
subl %edx, %eax # a = y - x
.L7:
popl %ebp # restore %ebp
ret # return
10. Example:
1 int absDiff(int x, int y)
2 {
3 int result;
4 if (x <= y) goto elsepoint;
5 result = x-y;
6 goto exitpoint;
7 elsepoint:
8 result = y-x;
9 exitpoint:
10 return result;
Comentários a estes Manuais