I wrote this program to compute multiple values of x, for a specific equation. My professor is going to set a break point in GDB at the label "done" and check the results. I have already done this and the results are correct, but the only problem is while debugging, GDB hits this break point at "done" 6 times (one for each x value). After hitting "c" to continue 6 times it finally exits. Why is GDB hitting this break point more than once? It should be running the "loop" 6 times, then finally reaching "done". Any ideas?
CODE
/*Constants are:*/
define(a2,56)
define(a1,14)
/*X and Y variable*/
define(x_r,l0)
define(y_r,l1)
define(x_max, l2)
define(y_max, l3)
.global main
main:
save %sp, -96, %sp
mov -2, %x_r
.global loop
loop:
cmp %x_r, 5 !Check if X is less than 5, if not jump to done.
bge done
mov %x_r, %o0 !This will compute x^6, the first part of equation
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %o0, %y_r !Completes first part, and stores in y.
mov %x_r, %o1 !This will compute 14x^2
mov %x_r, %o0
call .mul
nop
mov a1, %o1
call .mul
nop
sub %y_r, %o0, %y_r !completes first two parts of equation
mov a2, %o0 !computes 56x.
mov %x_r, %o1
call .mul
nop
add %y_r, %o0, %y_r !equation complete. Store result in y_r.
cmp %y_r, %y_max !Check to see if y_r is larger than previous.
bg update !If so, go to update
cmp %y_r, %y_max
ble loop
nop
update:
mov %y_r, %y_max !y_r was bigger, so it replaces y_max
mov %x_r, %x_max !the corresponding x_r replaces x_max
add %x_r, 1, %x_r !x++
ba loop !Go back to the loop.
done:
mov 1, %g1
ta 0