Translation between MIPS and Machine Code What arc the three
Solution
1-
R instructions are used when all the data values used by the instruction are located in registers.
All R-type instructions have the following format:
Where \"OP\" is the mnemonic for the particular instruction. rs, and rt are the source registers, and rd is the destination register. As an example, the add mnemonic can be used as:
Where the values in $s2 and $s3 are added together, and the result is stored in $s1. In the main narrative of this book, the operands will be denoted by these names.
R Format
opcode
The opcode is the machinecode representation of the instruction mnemonic. Several related instructions can have the same opcode. The opcode field is 6 bits long (bit 26 to bit 31).
rs, rt, rd
The numeric representations of the source registers and the destination register. These numbers correspond to the $X representation of a register, such as $0 or $31. Each of these fields is 5 bits long. (25 to 21, 20 to 16, and 15 to 11, respectively). Interestingly, rather than rs and rt being named r1 and r2 (for source register 1 and 2), the registers were named \"rs\" and \"rt\" because t comes after s in the alphabet. This was most likely done to reduce numerical confusion.
Shift (shamt)
Used with the shift and rotate instructions, this is the amount by which the source operand rs is rotated/shifted. This field is 5 bits long (6 to 10).
Funct
For instructions that share an opcode, the funct parameter contains the necessary control codes to differentiate the different instructions. 6 bits long (0 to 5). Example: Opcode 0x00 accesses the ALU, and the funct selects which ALU function to use.
I Instructions
I instructions are used when the instruction must operate on an immediate value and a register value. Immediate values may be a maximum of 16 bits long. Larger numbers may not be manipulated by immediate instructions.
I instructions are called in the following way:
Where rt is the target register, rs is the source register, and IMM is the immediate value. The immediate value can be up to 16 bits long. For instance, the addi instruction can be called as:
Where the value of $s2 plus 100 is stored in $s1.
I Format[edit]
I instructions are converted into machine code words in the following format:
Opcode
The 6-bit opcode of the instruction. In I instructions, all mneumonics have a one-to-one correspondence with the underlying opcodes. This is because there is no functparameter to differentiate instructions with an identical opcode. 6 bits (26 to 31)
rs, rt
The source and target register operands, respectively. 5 bits each (21 to 25 and 16 to 20, respectively).[1]
IMM
The 16 bit immediate value. 16 bits (0 to 15). This value is usually used as the offset value in various instructions, and depending on the instruction, may be expressed in two\'s complement.
J Instructions[edit]
J instructions are used when a jump needs to be performed. The J instruction has the most space for an immediate value, because addresses are large numbers.
J instructions are called in the following way:
Where OP is the mnemonic for the particular jump instruction, and LABEL is the target address to jump to.
J Format[edit]
J instructions have the following machine-code format:
Opcode
The 6 bit opcode corresponding to the particular jump command. (26 to 31).Opcode
Address
A 26-bit shortened address of the destination. (0 to 25). The two most LSBits are removed, and the 4 MSBits are removed, and assumed to be the same as the current instruction\'s address.
2- Hex code for the assembly language instruction is
3- it represents SUB $t2 $t0 $t1
its binary equivalent is 00000001000010010101000000100010
its purpose is to subtract 32-bit integers. If overflow occurs, then trap.
| opcode | rs | rt | IMM |
| 6 bits | 5 bits | 5 bits | 16 bits |

