Monash University > School of Computer Science and Software Engineering > CSE1303 > Part B > Tutorials > Tutorial B3
This tute covers material from lectures B07 to B09.
Attempt the questions marked (*) like this before the tutorial. If you have specific questions about unmarked questions, you can ask the tutor about them during the tutorial.
For these questions, you will need to review the instruction set of the MIPS computer by reading sections 2.4 through 2.10 of the SPIM manual.
Explain the difference, if any, between the implementations.
Explain why such an instruction might be useful. (Hint: I-type instructions have an immediate field of 16 bits. How would you perform the following 32-bit immediate load using no pseudoinstructions?
li $t0, 0x12345678
Note that you will need two instructions, one of them lui, to complete the operation.)
How would you complete the same load without the lui instruction? (Hint: this time you will need at least three instructions.)
Explain how these two instructions:
slt $at, $t0, $t1 bne $at, $zero, foo
are equivalent to this pseudoinstruction:
blt $t0, $t1, foo
Explain how multiplying two 32-bit registers can produce a 64-bit result. (Hint: multiply, in decimal if you prefer, two three-digit numbers and note the length of the result.)
Explain how this pseudoinstruction:
mul $t2, $t0, $t1
is expanded by the assembler into these two instructions:
mult $t0, $t1 mflo $t2
Suggest why the HI register can usually be safely ignored.
Using the tables and diagram at the end of this tutorial, show the encoding of the following instructions.
Using the same tables and diagram, determine the assembly language instructions that correspond to the following bit patterns.
There are three main formats for MIPS instructions, depending on whether the operands are
These are illustrated in the following diagram.
Note that there are some exceptions: for instance, shift instructions sll, srl and sra are R-format instructions, with the first source register unused and the number of bits to shift stored in the "shift amount" field.
This abridged table shows the bit patterns of instructions' opcodes (bits 31-26 of instruction word).
| opcode field (binary) | opcode field (decimal) | opcode | instruction format |
|---|---|---|---|
| 000000 | 0 | operation given in function field; see "Function" table | R-type |
| 000010 | 2 | j | J-type |
| 000011 | 3 | jal | J-type |
| 000100 | 4 | beq | I-type |
| 000101 | 5 | bne | I-type |
| 001000 | 8 | addi | I-type |
| 001001 | 9 | addiu | I-type |
| 001010 | 10 | slti | I-type |
| 001011 | 11 | sltiu | I-type |
| 001100 | 12 | andi | I-type |
| 001101 | 13 | ori | I-type |
| 001110 | 14 | xori | I-type |
| 001111 | 15 | lui | I-type |
| 100000 | 32 | lb | I-type |
| 100001 | 33 | lh | I-type |
| 100011 | 35 | lw | I-type |
| 100100 | 36 | lbu | I-type |
| 100101 | 37 | lhu | I-type |
| 101000 | 40 | sb | I-type |
| 101001 | 41 | sh | I-type |
| 101011 | 43 | sw | I-type |
This abridged table shows the bit patterns of the Function field (bits 5-0 of instruction word) for R-type instructions, where bits 31-26 are 0.
| function field (binary) | function field (decimal) | opcode |
|---|---|---|
| 000000 | 0 | sll |
| 000010 | 2 | srl |
| 000011 | 3 | sra |
| 000100 | 4 | sllv |
| 000110 | 6 | srlv |
| 000111 | 7 | srav |
| 001000 | 8 | jr |
| 001001 | 9 | jalr |
| 001100 | 12 | syscall |
| 010000 | 16 | mfhi |
| 010010 | 18 | mflo |
| 011000 | 24 | mult |
| 011001 | 25 | multu |
| 011010 | 26 | div |
| 011011 | 27 | divu |
| 100000 | 32 | add |
| 100001 | 33 | addu |
| 100010 | 34 | sub |
| 100011 | 35 | subu |
| 100100 | 36 | and |
| 100101 | 37 | or |
| 100110 | 38 | xor |
| 100111 | 39 | nor |
| 101010 | 42 | slt |
| 101011 | 43 | sltu |
This table lists general-purpose register numbers and their associated names.
| Register field (binary) | Register field (decimal) | Register name |
|---|---|---|
| 00000 | 0 | $zero |
| 00001 | 1 | $at |
| 00010 | 2 | $v0 |
| 00011 | 3 | $v1 |
| 00100 | 4 | $a0 |
| 00101 | 5 | $a1 |
| 00110 | 6 | $a2 |
| 00111 | 7 | $a3 |
| 01000 | 8 | $t0 |
| 01001 | 9 | $t1 |
| 01010 | 10 | $t2 |
| 01011 | 11 | $t3 |
| 01100 | 12 | $t4 |
| 01101 | 13 | $t5 |
| 01110 | 14 | $t6 |
| 01111 | 15 | $t7 |
| 10000 | 16 | $s0 |
| 10001 | 17 | $s1 |
| 10010 | 18 | $s2 |
| 10011 | 19 | $s3 |
| 10100 | 20 | $s4 |
| 10101 | 21 | $s5 |
| 10110 | 22 | $s6 |
| 10111 | 23 | $s7 |
| 11000 | 24 | $t8 |
| 11001 | 25 | $t9 |
| 11010 | 26 | $k0 |
| 11011 | 27 | $k1 |
| 11100 | 28 | $gp |
| 11101 | 29 | $sp |
| 11110 | 30 | $fp |
| 11111 | 31 | $ra |
Last modified 2002-07-03