Building an ALU

Tom Kelliher, CS 240

Feb. 15, 1999

Administrivia

Announcements

Assignment

Re-read 4.5, particularly fast addition.

From Last Time

Number representation.

Outline

  1. Sign extension & comparisons.

  2. Addition & subtraction.

  3. Logical operations: bit operations, shifts, masks.

  4. Building an ALU

Coming Up

Speeding up addition.

Representation Odd & Ends

  1. Sign Extension:
    1. How do you place a 16-bit signed immediate into a register?

    2. How do you load a signed byte into register?

    3. The sign extension algorithm.

    4. Load byte unsigned.

  2. Signed & unsigned comparison. Or, sometimes 1111 is less than 0000 and sometimes it's not.

Addition & Subtraction

  1. The addition table for a full binary adder:

  2. Subtraction is addition.

  3. Examples: Add/subtract in eight bits 97 (01100001), 51 (00110011); 26 (00011010), 15 (00001111). Demonstrate borrow subtraction, addition subtraction.

  4. Overflow: Adding two numbers of the same sign, the result should be of the same sign.

  5. Why does overflow occur?

  6. Prove that the sum of two numbers of opposite signs is always representable.

  7. Some languages care about overflow and some don't. Hardware exceptions.

Logical Operations

  1. The basics: truth tables for !, &, and |.

  2. Shift operations: right, arithmetic left, logical left.

    SHAMT in an R-format instruction.

  3. Rotate operations.

  4. Bit masks:
    1. A constant combined with a logical operation to set or reset bits in a word.

    2. What logical operation and bit mask should be used to clear the four least significant bits of a?

    3. What logical operation and bit mask should be used to set the four least significant bits of a?

    4. Avoiding the moral equivalent of the Y2K problem when constructing masks.

  5. Example to pull it all together: You have a word containing dog in ASCII. Modify it so that it contains Dog.

Building an ALU

Basic logic gates:

  1. Two-input AND gate.

    Constructing a larger fan-in gate from smaller gates.

  2. Two-input OR gate.

    Constructing a larger fan-in gate from smaller gates.

  3. Inverter.

  4. 2-1 Multiplexor.

    Symbol:

Truth table:

Remember: It is a switch.

A two function logical unit:

Constructing a 4-1 mux from 2-1 muxes.

One Bit Full Adder

Recall the addition table:

Write SOP equations for sum and carry-out. Minimize. Implement.

Block diagram:



Thomas P. Kelliher
Sun Feb 14 21:23:30 EST 1999
Tom Kelliher