Exercise 2.1
The following problems deal with translating
from C to MIPS. Assume that the variables g, h, i,
and j are given and already stored in registers, and could be
considered as 32-bit integers as declared (e.g. using int) in a
C program. Let f, g, etc., stand for registers in the
MIPS code you write.
a. | f = g + h + i + j; |
b. | f = g + (h + 5); |
The following problems deal with translating MIPS to C. Assume that
the variables f, g, and h are given and represent
specific registers in the MIPS code, and could be considered as 32-bit
integers as declared in a C program. (Modified slightly from problem in text.)
a. | add f, g, h |
b. | addi f, g, 1 |
add f, f, h |
Exercise 2.2
The following problems deal with translating from MIPS to C. Assume that
the variables f and h are given and represent
specific registers in the MIPS code, and could be considered as 32-bit
integers as declared in a C program.
a. | add f, f, h |
b. | sub f, $0, f |
addi f, f, 1 |
Exercise 2.4
The following problems deal with translating from C to
MIPS. Assume that the variables f, g, and h are
assigned to registers $s0, $s1, and $s2,
respectively. Assume that A and B are arrays of 32-bit
integers and that their base addresses are in registers $s6 and
$s7 respectively. Make use of temporary registers as
needed, but use only the minimum necessary. Treat the two statements
as independent, not sequential.
a. | f = g + h + B[4]; |
b. | f = g - A[B[4]]; |
Exercise 2.6
The following problems deal with translating from MIPS
to C. Assume that the variables f, g, h, and i are assigned to registers $s0, $s1, $s2, and
$s3 respectively. Assume that A is an array
of 32-bit integers and that its base addresses is in register $s6. (Modified slightly from problem in text.)
a. | add $s0, $s3, $s2 |
add $s0, $s0, $s3 | |
add $s0, $s0, $s1 |
b. | addi $s6, $s6, -20 |
add $s6, $s6, $s1 | |
lw $s0, 8($s6) |
Address | Value |
256 | 100 |
260 | 200 |
264 | 300 |
Find the value of $s0 at the end of execution of the assembly code in each case.