ECE 374: Computer Organization
More BasicsRepresenting Instructions
R-Format:
Opcode (op) | Source Register (rs) | Second Source Register (rt) | Destination Register (rd) | Shift Amount (shamt) | Function (funct) |
---|---|---|---|---|---|
6-bits | 5-bits | 5-bits | 5-bits | 5-bits | 6-bits |
Example
MIPS ASM: add $t0, $s1, $s2
Instruction:
special | \$s1 | \$s2 | \$t0 | 0 | add |
---|---|---|---|---|---|
0 | 17 | 18 | 8 | 0 | 32 |
000000 | 10001 | 10010 | 01000 | 00000 | 100000 |
$0000_0010_0011_0010_0100_0000_0010_00002$
$0232_4020{16}$
I-Format
Immediate format, for instructions with constants.
Opcode (op) | Source Register (rs) | Destination or Source Register (rt) | Constant or Address |
---|---|---|---|
6-bits | 5-bits | 5-bits | 16-bits |
Example
MIPS ASM: addi $t0, $t1, 10
Instruction:
addi | \$t1 | \$t0 | constant |
---|---|---|---|
8 | 9 | 8 | 10 |
001000 | 10001 | 10010 | 00000000_00001010 |
$0010_0010_0011_0010_0000_0000_0000_1010_2$
Logical Operations
Operation | C | Java | MIPS |
---|---|---|---|
Shift Left Logical | << | << | sll |
Shift Right Logical | >> | >>> | sll |
Bitwise And | & | & | and , andi |
Bitwise Or | | | | | or , ori |
Bitwise Not | ~ | ~ | nor |