Question: Help with RISC-V code, was told that below code has calling convention error, so no need to change the original code (add extra to fix

Help with RISC-V code, was told that below code has calling convention error, so no need to change the original code (add extra to fix it)

.data n: .word 2 exp: .word 10

.text main: # load the value of n into a0 la a0 n lw a0 0(a0)

# load the value of exp into a1 la a1 exp lw a1 0(a1)

# call pow jal pow

# prints the output of pow mv a1 a0 li a0 1 ecall # Print Result

# exits the program li a0 17 li a1 0 ecall

pow: # this function is a recursive pow function # a0 contains the base # a1 contains the power to raise to # the return value should be the result of a0^a1 # where ^ is the exponent operator, not XOR

# return 1 if a1 == 0 beq a1 x0 pow_zero_case

# otherwise, return pow(a0, a1-1) * a0 mv t0 a0 # save a0 in t0 addi a1 a1 -1 # decrement a1

jal pow # call pow(a0, a1-1)

mul a0 a0 t0 # multiply pow(a0, a1-1) by t0 # (which contains the value of a0)

j pow_end

pow_zero_case: li a0 1

pow_end: ret

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!