How to know if the opcode of the MIPS instruction is Register, Imidiate or Jump ?
Given this table from the book, but is there any way to define the format of the opcode ?
Take a look at the opcode bits - the most significant 6 bits. In C, if n is the 32-bit command dword, the expression for the opcode is (n >> 26) & 0x3f.
If opcode is 0, then it's a register command.
If it's 2 (j), 3 (jal), or 26 (trap) - it's a jump.
Else immediate.
A cheat sheet of MIPS encoding, including a list of all opcodes, is available here, and probably elsewhere.
Take a look at the opcode bits - the most significant 6 bits. In C, if
nis the 32-bit command dword, the expression for the opcode is(n >> 26) & 0x3f.If opcode is 0, then it's a register command.
If it's 2 (
j), 3 (jal), or 26 (trap) - it's a jump.Else immediate.
A cheat sheet of MIPS encoding, including a list of all opcodes, is available here, and probably elsewhere.