Arithmetic Logic Unit (ALU)
One circuit, six control bits, and eighteen useful functions.
One Chip, Many Operations
The Arithmetic Logic Unit (ALU) is the processor component that performs basic arithmetic and logical operations.
Instead of building a separate chip for every operation, the processor sends control bits to one shared chip. The same hardware is reused in different ways.
Data Inputs and Control Inputs
x[16]→y[16]→zxnxzynyfnoout[16]x, y, and out are sixteen-bit buses.
Each of the six control inputs is one bit.
Six control bits permit 26 = 64 control patterns.
What Do the Six Control Bits Do?
x[16]→y[16]→zxnxzynyfnoout[16]zx: zero thexinput.
Ifzxthenx = 0.nx: bitwise negatexinput.
Ifnxthenx = !x.zy: zero theyinput.ny: bitwise negateyinput.f: function code.
Iffthenout = x + y, the two's-complement addition.
Elseout = x & y, bitwise AND of the inputs.no: bitwise negate output.
Ifnothenout = !out.
Output Specification
- Chip name:
- ALU
- Data inputs:
x[16],y[16]- Control inputs:
zx, nx, zy, ny, f, no- Data output:
out[16]- Function:
if zx then x = 0 if nx then x = !x if zy then y = 0 if ny then y = !y if f then out = x + y else out = x & y if no then out = !out
When Both zx and nx Are True
x[16]→y[16]→zxnxzynyfnoout[16]If both zx and nx are set to true, the operations happen in order.
- First,
zxis implemented:x = 0. - Then,
nxis implemented:x = !x. - Therefore,
xbecomes all 1s. - In two's complement, all 1s represents
-1in decimal.
Similarly, the same sequence is applied to y when both zy and ny are true.
Example: Computing x − 1
Use the control pattern 0 0 1 1 1 0, corresponding to zx nx zy ny f no.
zx=0, nx=0Keep x.
zy=1, ny=1Zero y, then negate it: !0 = −1.
f=1Add: x+(−1).
no=0Keep x−1.
Every row in the ALU function table can be justified by tracing the same control steps.
Trace the Control Bits
For each control pattern, read the bits as zx nx zy ny f no, trace the transformations, and state the resulting function.
0 0 1 1 0 00 0 1 1 0 10 0 1 1 1 11 1 1 1 1 1A: x
B: !x
C: −x
D: 1
Find the Control Bits
Write the six-bit control pattern zx nx zy ny f no for each function.
x+1x-yx & yx | yNand(x,y)A 011111
B 010011
C 000000
D 010101
E 000001
Constants and Unary Functions
| zx | nx | zy | ny | f | no | out |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 | 0 | −1 |
| 0 | 0 | 1 | 1 | 0 | 0 | x |
| 1 | 1 | 0 | 0 | 0 | 0 | y |
| 0 | 0 | 1 | 1 | 0 | 1 | !x |
| 1 | 1 | 0 | 0 | 0 | 1 | !y |
| 0 | 0 | 1 | 1 | 1 | 1 | −x |
| 1 | 1 | 0 | 0 | 1 | 1 | −y |
| 0 | 1 | 1 | 1 | 1 | 1 | x+1 |
| 1 | 1 | 0 | 1 | 1 | 1 | y+1 |
| 0 | 0 | 1 | 1 | 1 | 0 | x−1 |
| 1 | 1 | 0 | 0 | 1 | 0 | y−1 |
Read each row from left to right as a sequence of control decisions.
Two-Input Arithmetic and Logic
| zx | nx | zy | ny | f | no | out |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 | x+y |
| 0 | 1 | 0 | 0 | 1 | 1 | x−y |
| 0 | 0 | 0 | 1 | 1 | 1 | y−x |
| 0 | 0 | 0 | 0 | 0 | 0 | x&y |
| 0 | 1 | 0 | 1 | 0 | 1 | x|y |
!( (!x) & (!y) ) = x | y by De Morgan's law.
Only 18 of the 64 possible control patterns are documented here. Other patterns may compute useful functions too.
Program the ALU
Write the six-bit control pattern zx nx zy ny f no for each function. Justify at least two answers by tracing the control steps.
out=0out=yout=x+1out=−yout=x−yout=x|yA 101010
B 110000
C 011111
D 110011
E 010011
F 010101
Design the ALU Functionality
Answer these as implementation questions. Name intermediate buses carefully.
Give a logic circuit for enabling the functionality of zx.
Enable the functions zx and nx.
Repeat the same design idea for zy and ny.
Show how f selects between x & y and x + y.
Show how no optionally negates the selected output.
Find a control pattern not listed in the function table and determine what it computes.
Build the Chapter 2 Chips
Use only the chips you gradually build in this lab and the chips from the previous week's lab. Test each chip before using it inside the next one.
A correct specification is your debugging guide: test the smallest transformation that could explain a failing output.
Arithmetic Logic Unit (ALU)
The ALU performs many arithmetic and logical operations.
Six inputs decide how x and y are prepared and which operation is selected.
Different control patterns produce constants, unary operations, arithmetic, AND, and OR.
The ALU is built compositionally from gates and adders already available.
The main idea is reuse: a single carefully controlled chip can stand in for many separate operations.
Lecture 8: From Computing to Remembering
Combinational chips compute from current inputs; the next challenge is preserving information over time.