Consider the following high-level recursive procedure: int f ( int n , int k ) {
ID: 3609061 • Letter: C
Question
Consider the following high-level recursive procedure: int f ( int n , int k ) { int b ;b=k+2; i f (n==0) b = 8 ; el se b = b + 4 n + f (n-1,k+1);
return b + k ; }
Translate the high-level procedure f into MIPS assemblylanguage. Pay particular attention to properly saving and restoringregisters across proce- dure calls; Use the MIPS preserved register convention; Clearly comment your code; Assume that the procedure starts at address 0x00400100; Keep local variable b in $s0 Consider the following high-level recursive procedure: int f ( int n , int k ) { int b ;
b=k+2; i f (n==0) b = 8 ; el se b = b + 4 n + f (n-1,k+1);
return b + k ; }
Translate the high-level procedure f into MIPS assemblylanguage. Pay particular attention to properly saving and restoringregisters across proce- dure calls; Use the MIPS preserved register convention; Clearly comment your code; Assume that the procedure starts at address 0x00400100; Keep local variable b in $s0
Explanation / Answer
Dear.... The variables n,k are paseed to registers $a0,$a1 the following is the mipscode... f: add$s0,$a0,2 cmp$a0,0 # comparingn,0 jneelse # if not truethen move to else block move$s0,8 # b = 8; add$s0,$a1 #b + k ja$ra # return $s0value j L1# go to the clean up and exitcode else:add$s0,$s0,4 sub $a0,1 add $a1,1 jmp f add $vo,$s0 L1: lw $ra, 20($sp)# the function returnsequence lw$fp, 16($sp) addu $sp,$sp,32 # Deallocating j $ra# And going home Hope this willhelp you... f: add$s0,$a0,2 cmp$a0,0 # comparingn,0 jneelse # if not truethen move to else block move$s0,8 # b = 8; add$s0,$a1 #b + k ja$ra # return $s0value j L1# go to the clean up and exitcode j L1# go to the clean up and exitcode j L1# go to the clean up and exitcode else:add$s0,$s0,4 sub $a0,1 add $a1,1 jmp f add $vo,$s0 L1: lw $ra, 20($sp)# the function returnsequence lw$fp, 16($sp) addu $sp,$sp,32 # Deallocating j $ra# And going home Hope this willhelp you... L1: lw $ra, 20($sp)# the function returnsequence lw$fp, 16($sp) addu $sp,$sp,32 # Deallocating j $ra# And going home Hope this willhelp you... L1: lw $ra, 20($sp)# the function returnsequence lw$fp, 16($sp) addu $sp,$sp,32 # Deallocating j $ra# And going home Hope this willhelp you...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.