In: Computer Science
How does one find the binary and hex for MIPS instructions. Such as, sub $s1, $t7, $t8 or lw $s1, 400($s5) ???
Greetings!!
Q1:sub $s1, $t7, $t8
Step 1: Identify the instruction format. Example:sub instruction is R-format.
Step 2: Get the instruction syntax Example: sub rd,rs,rt
Step 3: Get the instruction encoding format:
Opcode | rs | rt | rd | shamt | func |
6 bits | 5 bits | 5 bits | 5 bits | 5 bits | 6 bits |
Step 4:Add the binaries of the respective opcode and register numbers into the encoding format
Opcode | rs | rt | rd | shamt | func |
6 bits | 5 bits | 5 bits | 5 bits | 5 bits | 6 bits |
000000 | 00111 | 01000 | 00001 | 00000 | 100010 |
Step 5: Arrange the bits in group of 4 and write the hex equivalent. 0000 0000 1110 1000 0000 1000 0010 0010
0x00E8082
Q2:lw $s1, 400($s5)
Step 1: Identify the instruction format. Example:sub instruction is I-format.
Step 2: Get the instruction syntax Example: lw rt,imm(rs)
Step 3: Get the instruction encoding format:
Opcode | rs | rt | imm |
6 bits | 5 bits | 5 bits | 16 bits |
Step 4:Add the binaries of the respective opcode and register numbers into the encoding format
Opcode | rs | rt | imm |
6 bits | 5 bits | 5 bits | 16 bits |
100011 | 00101 | 00001 | 000000110010000 |
Step 5: Arrange the bits in group of 4 and write the hex equivalent. 1000 1100 1010 0001 0000 0001 1001 0000
0x8CA10190
Hope this helps