Building an ALU
Tom Kelliher, CS 240
Feb. 15, 1999
Re-read 4.5, particularly fast addition.
Number representation.
- Sign extension & comparisons.
- Addition & subtraction.
- Logical operations: bit operations, shifts, masks.
- Building an ALU
Speeding up addition.
- Sign Extension:
- How do you place a 16-bit signed immediate into a
register?
- How do you load a signed byte into register?
- The sign extension algorithm.
- Load byte unsigned.
- Signed & unsigned comparison. Or, sometimes 1111 is less than 0000
and sometimes it's not.
- The addition table for a full binary adder:

- Subtraction is addition.
- Examples: Add/subtract in eight bits 97 (01100001), 51 (00110011); 26
(00011010), 15 (00001111). Demonstrate borrow subtraction, addition
subtraction.
- Overflow: Adding two numbers of the same sign, the result should be
of the same sign.
- Why does overflow occur?
- Prove that the sum of two numbers of opposite signs is always
representable.
- Some languages care about overflow and some don't. Hardware
exceptions.
- The basics: truth tables for !, &, and
|.
- Shift operations: right, arithmetic left, logical left.
SHAMT in an R-format instruction.
- Rotate operations.
- Bit masks:
- A constant combined with a logical operation to set or reset bits
in a word.
- What logical operation and bit mask should be used to clear the
four least significant bits of a?
- What logical operation and bit mask should be used to set the
four least significant bits of a?
- Avoiding the moral equivalent of the Y2K problem when constructing
masks.
- Example to pull it all together: You have a word containing dog
in ASCII. Modify it so that it contains Dog.
Basic logic gates:
- Two-input AND gate.
Constructing a larger fan-in gate from smaller gates.
- Two-input OR gate.
Constructing a larger fan-in gate from smaller gates.
- Inverter.
- 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.
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