I need to learn how to do this. guidance please! review for a test for tonite. :
ID: 3609403 • Letter: I
Question
I need to learn how to do this.guidance please! review for a test for tonite. :(
Convert the C function below to MIPS assembly language. int sum( int* arr, int size ) { if ( size == 0 ) return 0 ; else return sum( arr, size - 1 ) + arr[ size - 1 ] ; } Assume that the argument is transferred in registers $a0 and$a1 and the result is returned in register $v0.
guidance please! review for a test for tonite. :(
Convert the C function below to MIPS assembly language. int sum( int* arr, int size ) { if ( size == 0 ) return 0 ; else return sum( arr, size - 1 ) + arr[ size - 1 ] ; } Assume that the argument is transferred in registers $a0 and$a1 and the result is returned in register $v0. Convert the C function below to MIPS assembly language. int sum( int* arr, int size ) { if ( size == 0 ) return 0 ; else return sum( arr, size - 1 ) + arr[ size - 1 ] ; } Assume that the argument is transferred in registers $a0 and$a1 and the result is returned in register $v0.
Explanation / Answer
please rate - thanks the 1st parameter is a reference parameter so you will have to getthe address from $a0, and get the value indirectly. The 2ndvalue is a number . so the code would be something like sorrythis is the best I can do move $t0, $a1 move itbecause you will be changing it later beq $t0,$0,return0 move$t1,$a0 save a0 addi$t0,-1 get size-1 add $t0,$t0,$t0 doublesize add $t0,$t0,$t0 quadruplesize to make it a word index lw$t1($t0) load arr[size-1] (not sure I'm lost with the recursion and how to save 2 sets ofparameters return0: move$v0,$0 return 0 in v0 jr$ra go back to where came from