Ive been trying to compute a problem.. looks like i have an infinite loop. Im new to Sparc Asm and using the GDB debugger has been a pain. On paper it looks like the program should run, but it doesnt and im completely stuck. This is far fetched but i hope someone can point me in the right direction. all the online resources are way to advanced for me.
what i am trying to compute is....
!y= 3x^4 - 17x^3 + 14x^2 - 23x + 23
!where X<12
!increment counter if y>0
!%o0 temp
!%o1 temp
!%o2 free
!%o3 3x^4
!%o4 17x^3
!%o5 3x^4-17x^3
!%o6 14x^2
!%o7 3x^4-17x^3+14x^2
!%l0
!%l1
!%l2 temporary counter used for x^*
!%l3 x counter
!%l4 23x
!%l5 3x^4-17x^3+14x^2-23x
!%l6 3x^4-17x^3+14x^2-23x-24--> y
!%l7 y (final answer) counter
.global main
main: save %sp, -64, %sp
clr %l3 !initialize counter for x
b test !begin testing
nop
power4:
clr %l2
mov %l3, %o1 !setup to compute x^4
mov %l3, %o0
call .mul
nop
cmp %l2, 4
ble power4 !using loop to compute 3X^4
add %l2, 1, %l2
mov 3, %o1
call .mul
nop
mov %o0, %o3 !storing 3x^4 in %o3
power3:
clr %l2
mov %l3, %o0 !setup to compute x^3
mov %l3, %o1
call .mul
nop
cmp %l2, 3 !using loop to compute
ble power3
add %l2, 1, %l2
mov 17, %o1
call .mul
nop
mov %o0, %o4 !storing 17x^3 to %o4
sub %o3, %o4, %o5 !(3x^4)-(17x^3) storing in %o5
power2:
clr %l2
mov %l3, %o0 !setup x^2
mov %l3, %o1
call .mul
nop
cmp %l2, 2 !using loop to perform x^2
ble power2
add %l2, 1, %l2
mov 14, %o1
call .mul
nop
mov %o0, %o6 !moving 14x^2-->%o6
add %o5, %o6, %o7 !Performing (3x^4)-(17x^3)+(14x^2)
mov 23, %o1 !setup to perform 23x
mov %l3, %o0
call .mul
nop
mov %o0, %l4 !23x
sub %o7, %l4, %l5 !(3x^4)-(17x^3)+(14x^2)-23x
sub %l5, 23, %l6 !final computation (3x^4)-(17x^3)+(14x^2)-23x-23
mov 0, %l7
cmp %l6, 0 !compares y if ans is >0
ble next
add %l7, 1, %l7 !increments counter if y>0
next: add %l3, 1, %l3 !increment counter
test: cmp %l3, 12 ! x<=12 ?
ble power4 ! go back to start
mov 1, %g1
tn 0
----------------------------
I did my best, thx
what i am trying to compute is....
!y= 3x^4 - 17x^3 + 14x^2 - 23x + 23
!where X<12
!increment counter if y>0
!%o0 temp
!%o1 temp
!%o2 free
!%o3 3x^4
!%o4 17x^3
!%o5 3x^4-17x^3
!%o6 14x^2
!%o7 3x^4-17x^3+14x^2
!%l0
!%l1
!%l2 temporary counter used for x^*
!%l3 x counter
!%l4 23x
!%l5 3x^4-17x^3+14x^2-23x
!%l6 3x^4-17x^3+14x^2-23x-24--> y
!%l7 y (final answer) counter
.global main
main: save %sp, -64, %sp
clr %l3 !initialize counter for x
b test !begin testing
nop
power4:
clr %l2
mov %l3, %o1 !setup to compute x^4
mov %l3, %o0
call .mul
nop
cmp %l2, 4
ble power4 !using loop to compute 3X^4
add %l2, 1, %l2
mov 3, %o1
call .mul
nop
mov %o0, %o3 !storing 3x^4 in %o3
power3:
clr %l2
mov %l3, %o0 !setup to compute x^3
mov %l3, %o1
call .mul
nop
cmp %l2, 3 !using loop to compute
ble power3
add %l2, 1, %l2
mov 17, %o1
call .mul
nop
mov %o0, %o4 !storing 17x^3 to %o4
sub %o3, %o4, %o5 !(3x^4)-(17x^3) storing in %o5
power2:
clr %l2
mov %l3, %o0 !setup x^2
mov %l3, %o1
call .mul
nop
cmp %l2, 2 !using loop to perform x^2
ble power2
add %l2, 1, %l2
mov 14, %o1
call .mul
nop
mov %o0, %o6 !moving 14x^2-->%o6
add %o5, %o6, %o7 !Performing (3x^4)-(17x^3)+(14x^2)
mov 23, %o1 !setup to perform 23x
mov %l3, %o0
call .mul
nop
mov %o0, %l4 !23x
sub %o7, %l4, %l5 !(3x^4)-(17x^3)+(14x^2)-23x
sub %l5, 23, %l6 !final computation (3x^4)-(17x^3)+(14x^2)-23x-23
mov 0, %l7
cmp %l6, 0 !compares y if ans is >0
ble next
add %l7, 1, %l7 !increments counter if y>0
next: add %l3, 1, %l3 !increment counter
test: cmp %l3, 12 ! x<=12 ?
ble power4 ! go back to start
mov 1, %g1
tn 0
----------------------------
I did my best, thx