In: Computer Science
Consider the following C code:
// write a MIPS instruction to initialize s0 to 6
t0 = ((s03 - 93)2 + s0 ) << 2
t1 = t0 / 4
Q2.1: Write a MIPS program that performs the operation of the above
C program.
Q2.2: What is the value of $t0 and $t1 after running your MIPS
program (write your answer in a comment at the end of the
code).
Submit your answer to Q2 in a file named A2_Q2.asm
ANSWER :
MIPS code
addi $s0, $0 , 6 //$s0 = 6
add $t0, $s0 , $0 //$t0 = $s0
mult $t0, $s0
mflo $t0 //$t0 =
($s0)^2
mult $t0, $s0
mflo $t0 //$t0 =
($s0)^3
addi $t0, $t0, -93 //$t0 = ($s0)^3 -
93
mult $t0, $t0
mflo $t0 //$t0 =
(($s0)^3 - 93)^2
add $t0, $t0, $s0 //$t0 = (($s0)^3 -
93)^2 + $s0
sll $t0, $t0, 2
//$t0 = ((($s0)^3 - 93)^2 + $s0) << 2
srl $t1, $t0, 2
//$t1 = $t0/4
$t0 = 60540
$t1 = 15135
( PLEASE VOTE FOR THIS ANSWER )
I THINK IT WILL BE USEFULL TO YOU .......
PLZZZZ COMMENT IF YOU HAVE ANY PROBLEM I WILL TRY TO SOLVE IT ............
THANK YOU .........