For More Practice
For More Practice
For More Practice
20-1
Instruction Formats
2.1 [15] <§2.4> Using the MIPS program in Exercise 2.34 (with bugs intact),
determine the instruction format for each instruction and the decimal values of
each instruction field.
while (save[i] == k)
i = i += 1;
on page 72 uses both a conditional branch and an unconditional jump each time
through the loop. Only poor compilers would produce code with this loop over-
head. Rewrite the assembly code so that it uses at most one branch or jump each
time through the loop. How many instructions are executed before and after the
optimization if the number of iterations of the loop is 10 (i.e., save[i + 10 * j]
do not equal k and save[i], . . . , save[i + 9 * j] equal k)?
ond is the address at which to write a result string in register $a1. Then itoa
should convert its first argument to a null-terminated decimal ASCII string and
store that string at the given result location. The return value from itoa, in reg-
ister $v0, should be a count of the number of nonnull characters stored at the
destination.
Translating MIPS to C
2.26 C/Java versus MIPS: Which statements (if any) are false?
1. Assignment statements: One variable on left-hand side in C/Java; one
variable (register) is destination in MIPS.
2. Assignment statements: Any number of variables on right-hand side in
C/Java; 1 or 2 (registers) source in MIPS.
3. Comments: /* ... */ in C/Java; // to end of line in Java; and
# to end of line in MIPS
4. Variables: declared in C/Java; no declaration in MIPS.
5. Types: Associated with declaration in C/Java (normally); associated with
instruction (operator) in MIPS.
FMP 2.20-4 For More Practice
C: 2 of ($s0,$sp,$v0,$t0,$a0,$ra)
D: 3 of ($s0,$sp,$v0,$t0,$a0,$ra)
E: 4 of ($s0,$sp,$v0,$t0,$a0,$ra)
F: 5 of ($s0,$sp,$v0,$t0,$a0,$ra)
MIPS Pseudoinstructions
2.39 Suppose
E: –15 –1
F: –15 –255