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
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
The following SPARC program finds the product of an integer raised to a passed in power....