Lecture 7 | Boolean Arithmetic

Arithmetic Logic Unit (ALU)

One circuit, six control bits, and eighteen useful functions.

Arithmetic Logic Unit

One Chip, Many Operations

Programs request operationsadd, subtract, AND, OR, negate...
Control signals encode the requesta small bit pattern
The ALU computes the resulton fixed-width data

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.

Hack ALU

Data Inputs and Control Inputs

x[16]y[16]
zxnxzynyfno
Hack ALUcontrol bits determine f(x,y)
out[16]
Data

x, y, and out are sixteen-bit buses.

Control

Each of the six control inputs is one bit.

Capacity

Six control bits permit 26 = 64 control patterns.

Hack ALU

What Do the Six Control Bits Do?

x[16]y[16]
zxnxzynyfno
Hack ALUcontrol bits determine f(x,y)
out[16]
  • zx: zero the x input.
    If zx then x = 0.
  • nx: bitwise negate x input.
    If nx then x = !x.
  • zy: zero the y input.
  • ny: bitwise negate y input.
  • f: function code.
    If f then out = x + y, the two's-complement addition.
    Else out = x & y, bitwise AND of the inputs.
  • no: bitwise negate output.
    If no then out = !out.
Hack ALU

Output Specification

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
Hack ALU

When Both zx and nx Are True

x[16]y[16]
zxnxzynyfno
Hack ALUcontrol bits determine f(x,y)
out[16]

If both zx and nx are set to true, the operations happen in order.

  1. First, zx is implemented: x = 0.
  2. Then, nx is implemented: x = !x.
  3. Therefore, x becomes all 1s.
  4. In two's complement, all 1s represents -1 in decimal.

Similarly, the same sequence is applied to y when both zy and ny are true.

Hack ALU

Example: Computing x − 1

Use the control pattern 0 0 1 1 1 0, corresponding to zx nx zy ny f no.

x preparationzx=0, nx=0

Keep x.

y preparationzy=1, ny=1

Zero y, then negate it: !0 = −1.

functionf=1

Add: x+(−1).

outputno=0

Keep x−1.

Every row in the ALU function table can be justified by tracing the same control steps.

Exercise 1

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.

A0 0 1 1 0 0
B0 0 1 1 0 1
C0 0 1 1 1 1
D1 1 1 1 1 1

A: x

B: !x

C: −x

D: 1

Exercise 3

Find the Control Bits

Write the six-bit control pattern zx nx zy ny f no for each function.

Ax+1
Bx-y
Cx & y
Dx | y
ENand(x,y)

A 011111

B 010011

C 000000

D 010101

E 000001

Hack ALU Functions

Constants and Unary Functions

zxnxzynyfnoout
1010100
1111111
111010−1
001100x
110000y
001101!x
110001!y
001111−x
110011−y
011111x+1
110111y+1
001110x−1
110010y−1

Read each row from left to right as a sequence of control decisions.

Hack ALU Functions

Two-Input Arithmetic and Logic

zxnxzynyfnoout
000010x+y
010011x−y
000111y−x
000000x&y
010101x|y
Why does the final row produce OR?

!( (!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.

Exercise 2

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.

Aout=0
Bout=y
Cout=x+1
Dout=−y
Eout=x−y
Fout=x|y

A 101010

B 110000

C 011111

D 110011

E 010011

F 010101

Exercise 4

Design the ALU Functionality

Answer these as implementation questions. Name intermediate buses carefully.

1

Give a logic circuit for enabling the functionality of zx.

2

Enable the functions zx and nx.

3

Repeat the same design idea for zy and ny.

4

Show how f selects between x & y and x + y.

5

Show how no optionally negates the selected output.

6

Find a control pattern not listed in the function table and determine what it computes.

Laboratory Preparation

Build the Chapter 2 Chips

1HalfAdder
2FullAdder
3Add16
4Inc16
5ALU
Allowed building blocks

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.

Summary of This Lecture

Arithmetic Logic Unit (ALU)

One chip

The ALU performs many arithmetic and logical operations.

Control bits

Six inputs decide how x and y are prepared and which operation is selected.

Functions

Different control patterns produce constants, unary operations, arithmetic, AND, and OR.

Construction

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.

Next Lecture | Sequential Logic

Lecture 8: From Computing to Remembering

Combinational chips compute from current inputs; the next challenge is preserving information over time.