For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, and I are assigned to registers $s0 - $s3, respectively. Assume that the base address of arrays X, Y, and Z are in registers $s4 - $s6, respectively. Be conservative and use a single temp register as possible. It is a C arithmetic command with two source operands and a destination. Each part is 3 points.
Add |
$t0, $s0, $s1 |
addi |
$t0, $t0, -1 |
sll |
$t0, $t0, 2 |
add |
$t0, $s4, $t0 |
lw |
$t0, 0($t0) |
sub |
$t1, $s2, $s3 |
addi |
$t1, $t1, -1 |
sll |
$t1, $t1, 2 |
add |
$t1, $s5, $t1 |
lw |
$t1, 0($t1) |
add |
$t0, $t0, $t1 |
add |
$t1, $s1, $s2 |
sll |
$t1, $t1, 2 |
add |
$t1, $t1, $s6 |
sw |
$t0, 0($t1) |
f: $s0
g: $s1
h: $s2
i: $s3
X: $s4
Y: $s5
Z: $s6
Lets assume temp = $t0
temp1 = $t1
ADD $t0, $s0, $s1 # Add $s0, $s1, and store in $t0:
temp = f+g
ADDI $t0, $t0, -1 # Decrement $t0: $t0 = $t0 - 1, or temp--
SLL $t0, $t0, 2 # Shift Left $t0 by 2 bits: temp = temp
<< 2
ADD $t0, $s4, $t0 # Add $s4, $t0, and store in $t0:
temp = temp + X[0], or temp += X[0]
LW $t0, 0($t0) # Load from $t0 to $t0: temp = temp
(This doesn't make much sense.)
SUB $t1, $s2, $s3 # Subtract $s3 from $s2, and store in $t1: temp1
= h - i
ADDI $t1, $t1, -1 # Decrement $t1: $t1 = $t1 - 1, or
temp1--
SLL $t1, $t1, 2 # Shift Left $t1 by
2 bits: temp1 = temp1 << 2
ADD $t1, $s5, $t1 # Add $s5, $t1, and store in $t1:
temp1 = temp1 + Y[0], or temp1 += Y[0]
LW $t1, 0($t1) # Load from $t1 to
$t1: temp1 = temp1 (This doesn't make much sense.)
ADD $t0, $t0, $t1 # Add $t0, $t1, and store in $t0:
temp = temp + temp1, or temp += temp1
ADD $t1, $s1, $s2 # Add $s1, $s2, and store in $t1:
temp1 = g + h
SLL $t1, $t1, 2 # Shift Left $t1 by
2 bits: temp1 = temp1 << 2
ADD $t1, $t1, $s6 # Add $t1, $s6, and store in $t1:
temp1 = temp1 + Z[0], or temp1 += Z[0]
SW $t0, 0($t1) # Store
Word $t1 into $t0: temp = temp1
Get Answers For Free
Most questions answered within 1 hours.