Skip to main content
Engineering LibreTexts

5.2: The ALU

  • Page ID
    27267
  • \( \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 ALU for this unit supports addition and subtraction, and also implements a flag to tell if the current operation produced an overflow. And overflow occurs when two number are added which are too big to be stored in the implemented 16 bit integers in the CPU. For example, adding 27000 + 25000 = 52000, a value larger than the maximum integer that can be handled, which is 32767. Likewise -27000 + -25000 = -52000, a number that is too below the minimum integer that can be handled, which is -32768. How the ALU handles these situations will be discussed later.

    A simple ALU that would implement only 16-bit addition is easy to implement, and is shown in the following figure. Two 16-bit values ($ac and Y) are sent to the CPU, and an adder is used to add the values and produce a result.

    Figure 5-2: Simple Adder

    Screen Shot 2020-07-03 at 12.20.58 PM.png

    To create implement subtraction, a bit of creative mathematics is used.

    1. RememberthatX⊕0=X;andX⊕1=X’.
    2. Simple arithmetic says X + Y = X + (-Y)
    3. -Y = Y’ + 1 (2’s complement negation operation).
    4. Subtraction can be implemented by taking each bit of Y, XORing it with 1 (getting the completment), then adding 1. To add 1, pass this bit into the carry in of the adder.
    5. Addition can be implemented by taking each bit of Y, XORing it with 0 (so it doesn’t change) and adding 0. To add 0, pass this bit into the carry in of the adder.
    6. Thus an Add/Subtract unit can be implemented by passing in a flag bit. If the bit is 0, an add operation is performed; if the bit is 1, a subtract operation is performed.

    This procedure is implemented in the following Logisim circuit. Note that all it does is XOR the Y bits with the flag value 0/1, and then add the flag to the adder via the carry in to the adder.

    Figure 5-3: Adder/Subtracter

    Screen Shot 2020-07-03 at 12.24.30 PM.png

    There is one last addition to be made to the ALU. We want to check if there is an overflow or not. The easiest way to do this is to check the carry-in and carry-out bits to the last full adder. If they are the same, there is no overflow, but if they are different, then overflow occurred. These two bits can be checked by using an XOR gate. If they are the same (no overflow), the XOR will produce 0, and if they are different (overflow) the XOR will produce 1.

    Figure 5-4: Adder/Subtracter with overflow

    Screen Shot 2020-07-03 at 12.27.40 PM.png


    This page titled 5.2: The ALU 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.

    • Was this article helpful?