In: Computer Science
Assume that the variables w, x, y, and z are stored in memory locations 16, 32, 48, and 128 respectively. Translate the following algorithmic operations into MIPS language equivalents:
[Assume $s1 is the base register, and $s1 contains the address of memory location 0]
if ((x – y) ³ w) then
set x to y
else:
set x to z
endif
C
code
if ((x – y)³ < w) then
set x to y
else:
set x to z
endif
MIPS Code
lw $t1, 16($s1)
//$t1 = w
lw $t2, 32($s1) //$t2 =
x
lw $t3, 48($s1) //$t3 =
y
sub $t2, $t2, $t3 //$t2 = (x-y)
mult $t2, $t2
mfhi $t4 //$t4 =
(x-y)^2
mult $t4, $t2
mfhi $t4 //$t4 =
(x-y)^3
slt $t2, $t4, $t1 //if((x-y)^3 < w)
$t2 = 1
beq $t2, $zero, Else //if($t2 = 0) Branch
to Else
sw $t3, 32($s1) // x =
y
Else:
lw $t3, 128($s1) //$t3 = z
sw $t3, 32($s1) // x =
z