Write the MIPS for the function with the following signature
Solution
Solution ::
main: // main body
// initialize the values to the 3 registers
addi $a0,$zero,10
jal sum // calling method
// Print out summation upto the number 10
li $v0,1 // print the integer
add $a1,$v0,$zero // load the return value into the argument
syscall
li $v0,10 // Exit here
syscall
sum: // sum body
addi $sp,$sp,-8 // allocate the space on the stack
sw $ra,0($sp) // store the return address (ra)
sw $a0,4($sp) // store the arguments
slti $t0,$a0,1 // check if the n > 0
beq $t0,$0,recurse // it is n > 0 case
add $v0,$0,$0 // start the return value to 0
addi $sp,$sp,8 // pop the 2 items off the stack
jr $ra // return to the caller
recurse:
addi $a0,$a0,-1 // calculate the n-1
jal sum // recursively the call sum(n-1)
lw $ra,0($sp) // restore the saved return address
lw $a0,4($sp) // restore the saved argument
addi $sp,$sp,8 // pop the 2 items off the stack
add $v0,$a0,$v0 // calculate the n + sum(n-1)
jr $ra // return to the caller
/// *** Thank You *** ///
![Write the MIPS for the function with the following signature: int getsum(int B[], int start, int end). This function will calculate the sum of all the values w Write the MIPS for the function with the following signature: int getsum(int B[], int start, int end). This function will calculate the sum of all the values w](/WebImages/39/write-the-mips-for-the-function-with-the-following-signature-1119873-1761595723-0.webp)