Question

The following SPARC program finds the product of an integer raised to a passed in power....

The following SPARC program finds the product of an integer raised to a passed in power. There are errors; fix them so that the code correctly runs.

.global exponent
exponent: save %fp, -96, %fp
   ! %i0 = the base number
     ! %i1 = holds the power
     cmp $i0, %g0
     ble expoDone
     mov 1, %l0
loopExpo:
     cmp %i1, %g0
     bge expone
     mov %i0, %o0
     call .mul
     mov %l0, %o1

     mov %g0, %l0
     ba loopExpo
     inc %i1
expoDone:
     mov %l0, %o0
     ret
     return

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The issue is with the branch instruction used in the code. We are branching to some branch which does no exist.

bge expone (there is no branch named expone)

It should branch to expDone

The code should be modified as :

.global exponent
exponent: save %fp, -96, %fp
   ! %i0 = the base number
     ! %i1 = holds the power
     cmp $i0, %g0
     ble expoDone
     mov 1, %l0
loopExpo:
     cmp %i1, %g0
     bge expoDone
     mov %i0, %o0
     call .mul
     mov %l0, %o1

     mov %g0, %l0
     ba loopExpo
     inc %i1
expoDone:
     mov %l0, %o0
     ret
     return

Add a comment
Know the answer?
Add Answer to:
The following SPARC program finds the product of an integer raised to a passed in power....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT