Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2.7: Convert following c code to MIPS assembly code ################################# int multiply(int multiplier, int multiplicand){ return multiplier*multiplicand; } int power(int base,int exponent){ int result=1;

Question 2.7: Convert following c code to MIPS assembly code

#################################

int multiply(int multiplier, int multiplicand){

return multiplier*multiplicand;

}

int power(int base,int exponent){

int result=1;

for(int i=0;i

result=multiply(base,result):

}

return result;

}

int main(){

int p=power(2,16);

return 0;

}

#################################

Given Instructions in MIPS Code:

initialize:

li $s0, 2 # provide some initial value for base

li $s1, 3 # provide some initial value for exponent

main:

#

# Insert your call to power here

#

j exitProgram # jump to exit label to terminate program

multiply:

# insert your multiply procedure here

mul $v0,$a0,$a1

jr $ra

power:

# Adjust stack as necessary and store preserved registers

# initialize local variables

# loop to compute result

# Restore preserved registers and restore stack point

# return to caller

##################################

registers $s0 and $s1 are populated with the base and exponent values respectively. Change these values as necessary to test your code

multiply procedure must return value into registers $v0-$v1 to pass the value back to the caller. Implement the power procedure, doing all multiplication by calling the multiple procedure.

Do NOT use any $tX registers in your power procedure or in your multiply procedure. In your power procedure, use register $s0 to store the result variable. Use register $s1 to store the iteration variable i. You may need additional $sX registers. Be sure to preserve any and all $sX registers that you use.

After your power procedure returns to main, move the final return value into the $s2 register.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions