Search code examples
assemblymipsmachine-codeopcode

In MIPS assembly, how do we know what function the opcode refers to if it starts with 000000?


Sorry for this stupid question.

For example, if I have 0x00812022 why is it

SUB $a0, $a0, $at

And not

ADD $a0, $a0, $at

According to the MIPS reference data, it says

add Opcode: 0/20 Hex

sub Opcode: 0/22 Hex

How do I differentiate between all opcodes that start with 000000?


Solution

  • R-type instructions have a funct field which further specifies the operation.

    R-type encoding

    add Opcode: 0/20 Hex

    This means the op field is zero, and the funct field is 0x20.