Skip to main content
Engineering LibreTexts

4.3: Machine Code for the Sub Instruction

  • Page ID
    27115
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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.


    This page titled 4.3: Machine Code for the Sub Instruction is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Charles W. Kann III.

    • Was this article helpful?