c p u ville logo
Donn Stewart
13917 Deviar Dr
Centreville, VA 20120
dstew@cpuville.com

Designing, Building, and Selling Obsolete Computers -- for Educational Purposes -- since 2004

c p u ville logo menu icon

8-bit Processor Arithmetic-Logic Unit (ALU) Design

The ALU is the easiest part of the computer to design and build. It is a large piece of combinational logic, which receives an input, and (after a short time) produces a corresponding output. It contains no registers, and has no "state", that is, for a given input, it will always produce the same output.

There are several kinds of inputs to the ALU. First, there are the data bytes A and B, which are to be added, subtracted or operated on logically. Next is the carry-in, which comes from a flip-flop on the data path. Usually this will be the carry-out from a prior arithmetic operation. Then there is the ALU opcode, which tells the ALU which operation to perform. The ALU opcode in my computer is derived directly from the machine language opcodes for the arithmetic-logical instructions. In fact, it is the lower 3 bits of the 5-bit opcode. A three-bit ALU opcode means that the ALU may perform 8 operations. The operations I wanted it to perform are add, add with carry, subtract, subtract with borrow, NOT, AND, OR, and XOR. The corresponding ALU opcodes will be 0 to 7 respectively.

The ALU works by performing all the operations simultaneously on the input operands, but only the desired operation's result is passed to the ALU output. This is done by a multiplexor (data selector) that is controlled by the ALU opcode, through a small bit of logic circuitry. Here is a drawing of the ALU design:

ALU design

Although not shown on the drawing, the A and B inputs are each 8 bits, the ALU opcode is 3 bits, and the carry-in is one bit. The ALU logic produces outputs that control the multiplexors that select the carry-in, whether or not B is inverted (for subtraction), whether or not there is a borrow (essentially a subtract one operation), and the ALU output. Here is a summary of the ALU logic operations (with active-low ALU opcodes):

ALU logic table

There is another small bit of logic that determines the carry-out. This is needed because the carry-out from the first adder in the subtract-with-borrow operation will not produce the correct carry-out in the case where A=B and there is a borrow to subtract. The logic equation for the carry-out logic is:

CarryOut = (NOT(BorrowSelect) AND AdderCarryOut) OR (AdderCarryOut AND BorrowCarryOut)


8-bit processor links:

menu icon