Skip to main content
Engineering LibreTexts

5.3: Adding the MLA instruction to the MSCPU

  • Page ID
    76116
  • \( \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}}\)

    The main advantage of the MSCPU architecture is that it allows new and more complex/powerful operations in hardware. Consider a very common case where a program wants to calculate an element address (ea) for an element in the array. Knowing the Base Address (ba) of the array, the size of each element (size), and the index number (idx), the following formula will calculate the array address for that element.

        ea = ba + (size * idx)
    

    The MSCPU has put the multiply unit in front of the ALU. Over two cycles it runs the multiplication operation (cycle 1) and addition operation (cycle 2). Thus, in one instruction the CPU can calculate the ea using the Multiply and Accumulate (mla) instruction. For example, if ba = 20, size = 4, and the index = 3, the address of array element 3 can be calculated by the following code fragment.

        MOV r1, #20
        MOV r2, #4
        MOV r3, #3
        MLA r0, r2, r3, r1  // The element address (ea) is in r0
    

    This MLA instruction tells the CPU to multiply r2 * r3, add the result to r1, and then store the result in r0. This will be done in two cycles. The first cycle multiplies Rs * Rm and passes the value on to a multiplexer, which selects the multiply unit result to forward to the ALU.

    Screen Shot 2022-03-24 at 3.25.56 PM.png

    Figure 27: MSCPU MLA operation - Step 1

    In the second step, the value register, Rn, is placed on the A bus. The value of the register Rn and the result of the multiplication are passed to the ALU, which adds the values, and passes the result back to the Register Bank to be stored in register Rd.

    Screen Shot 2022-03-24 at 3.26.46 PM.png

    Figure 28: MSCPU MLA operation - Step 2

    Since this instruction requires two operation units, the multiplier and the ALU, this instruction requires 2 cycles, or has a CPI=2.

    The format for the MLA instruction is:

        MLA Rd, Rm, Rs, Rn
    

    An example of using the mla instruction is the same as given above.

        MLA r0, r2, r3, r1

    This page titled 5.3: Adding the MLA instruction to the MSCPU is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Charles W. Kann III via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.