Homework Assignment #2 – MIPS Instructions
CDA 3100, Computer Organization I
Submission: A hard copy required.
Problem 1 (30 points)
Exercise 2.4.1(p. 182).
The following problems deal with translating from C to MIPS. Assume that the variables
f,g,h,i,
and j are assigned to registers
$s0, $s1, $s2, $s3
, and
$s4
, respectively.
Assume that the base address of the arrays
A
and
B
are registers
$s6
and
$s7
, respectively.
a. f=g+h+B[4]
b. f=g-A[B[4]]
2.4.1. For the C statements above, what is the corresponding MIPS assembly code?
Solution:
2.4.1
a.
f=g+h+B[4]
add $s0, $s1, $s2
lw $t0, 16($s7)
add $s0, $s0, $t0
b. f=g-A[B[4]]
lw $t0, 16($s7)
sll $t0, $t0, 2
add $t0, $t0, $s6
lw $t0, 0($t0)
sub $s0, $s1, $t0
Problem 2 (10 points)
Exercise 2.16.1 (p. 194).
For these problems, there are various binary values for register
$t0
. Given the value for
$t0
,
you will be asked to evaluate the outcome of different branches.
a.