Anyone know how to do this? Here\'s how it works: What is the C equivalent of th
ID: 3546604 • Letter: A
Question
Anyone know how to do this? Here's how it works:
What is the C equivalent of the following MIPS subroutine? Assume that the functions's parameters are integers named a, b, c, etc. in the C version of the function. You need to determine how many parameters this subroutine has.
funfunc: addi $sp, $sp, -8
sw $s0, 4($sp)
sw $s1, 0($sp)
move $so, $0
addi $s1, $0, 1
move $v0, $0
loop: bge $s0, $a0, End
add $v0, $v0, $s1
sll $s1, $s1, 1
addi $s0, $s0, 1
j loop
End: lw $s1, 0($sp)
lw $s0, 4($sp)
addi $sp, $sp, 8
jr $ra
Explanation / Answer
C function:
int sum(int n) /* $a0 */
{
int i = 0; /* $s0 */
int val = 1; /* $s1 */
int sum = 0; /* $v0 */
while (i < n)
{
sum += val;
val *= 2;
i++;
}
return sum;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.