×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

sparc,asm,loop simple problem - can someone look at my code?

sparc,asm,loop simple problem - can someone look at my code?

sparc,asm,loop simple problem - can someone look at my code?

(OP)
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
Replies continue below

Recommended for you

RE: sparc,asm,loop simple problem - can someone look at my code?


First you can use the horner-rule. Then you need no loops, you save a few multplikations, and gets a more accurat result.

y= 3x^4 - 17x^3 + 14x^2 - 23x + 23
y= (((3*x- 17)*x + 14)*x - 23)*x + 23; ==> only 4 multiplies


anyway the endless-loops in your code is the wrong set af the label power4, power3 and power2.

<b><tt>  clr %l2</tt></b>
<b><tt>power4:</tt></b>
  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         

the same in the other loops. But try to implement the horner-rule.

RE: sparc,asm,loop simple problem - can someone look at my code?

(OP)
ahh thank you I see it now, it was clearing each time. I changed the code up.. tried to run it .. it crashed

Program received signal SIGSEGV, Segmentation fault.
0x1068c in power2 ()

(gdb) p $l3
$1 = 33519

that cant be right it should have stopped long ago. Ill keep working at it, thanks for the tip!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close