For this part we will be porting your code from Part IV into a function doubleSu
ID: 3711894 • Letter: F
Question
For this part we will be porting your code from Part IV into a function doubleSum(). This function now takes the variable z as a parameter, and returns w at the end. You should convince yourself that this code computes twice the sum of all integers from 0 to z: public int doubleSum (int z) f int w, x 0; w - 2*x; return w 1. Translate this function to MIPS. Note this must behave as a function that can be called from anywhere. and cannot assume anything about the caller. Some register assignments may also change (10 pts).Explanation / Answer
doubleSum: # Since there are no recursive calls we don't need to save anything on stack addi $s0, $0, 0 # w = 0 addi $s1, $0, 0 # x = 0 addi $s2, $0, 0 # y = 0 loop: bgt $s2, $a0, end add $s1, $s1, $s2 # x=x+y; addi $s2, $s2, 1 # y++ j loop end: sll $s0, $s1, 1 # w = 2*x add $v0, $0, $s0 # $vo = w jr $ra
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.