Skip to main content
Engineering LibreTexts

4.3: Machine Code for the Sub Instruction

  • Page ID
  • This section will translate the following sub instruction to machine code.

    sub $s0, $s1, $s2

    The MIPS Greensheet specifies the sub instruction as an R-format instruction and the op- code/function for the sub as 0/22. This means the 6 bits for the op code are 000000 and the 6 bits for the function are 100010.

    Register Rd is $s0 is also register $16, or 10000.

    Register Rs is $s1 is also register $17, or 10001.

    Register Rt is $s2 is also register $18, or 10010.

    The shamt is 00000 as there are no bits being shifted.

    The result is the following R-format instruction.

    Figure 4-5: Machine code for sub $s0, $s1, $s2

    Screen Shot 2020-06-29 at 7.52.32 PM.png

    To write this instruction's machine code, the bits are organized in groups of 4, and hex values given. This results in the number 0000 0010 0011 0010 1000 0000 0010 00102 or 0x02328022.

    • Was this article helpful?