Reading
H+P Chapter 3, sections 4, 6, and 8-10.
To do on your own
Fill in this chart:
binary | hexadecimal | decimal |
---|---|---|
293 | ||
1708 | ||
0x87a4 | ||
0xff0c | ||
1100 1010 1111 1110 | ||
1111 1010 1101 1110 |
To be turned in
1. Suppose $a0 contains 200 and $a1 contains 4. Also suppose that part of memory contains these values:
address | contents |
---|---|
200 | 4 |
204 | 9 |
208 | 7 |
212 | 1 |
216 | 3 |
outer: addi $t0, $zero, 1 add $t1, $zero, $zero inner: add $t2, $t1, $t1 add $t2, $t2, $t2 add $t2, $t2, $a0 lw $t3, 0($t2) lw $t4, 4($t2) slt $t5, $t4, $t3 beq $t5, $zero, skip sw $t4, 0($t2) sw $t3, 4($t2) add $t0, $zero, $zero skip: addi $t1, $t1, 1 slt $t5, $t1, $a1 bne $t5, $zero, inner beq $t0, $zero, outer
For some op values, other fields in the instruction are used in combination with the opcode. For example, when op=0, the last six bits of the instruction -- the "funct" field in R-format -- further specify the operation. How many operations can be encoded using either opcode alone or (opcode=0 and funct)?
3. H+P 3.4 and 3.5
Note: For problem 3.5, you need to load a 32-bit constant into a register. See the example on page 147.
4. As discussed on page 157 and summarized in Figure 3.37, pseudoinstructions are not part of the MIPS instruction set but often appear in MIPS programs. For each pseudoinstruction in the following table, produce a minimal sequence of actual MIPS instructions to accomplish the same thing. You may need to use $at for some of the sequences. For the beq line, assume that "number" is a number that can be represented with 16 bits.
Note: You may need to use the "li" instruction, which stands for load immediate. See page A-59.
Pseudoinstruction | What it accomplishes |
---|---|
move $t5, $t3 | $t5 = $t3 |
clear $t5 | $t5 = 0 |
beq $t5, number, L | if ($t5 == number) go to L |
ble $t5, $t3, L | if($t5 <= $t3) go to L |
bgt $t5, $t3, L | if($t5 > $t3) go to L |
bge $t5, $t3, L | if($t5 >= $t3) go to L |