DEV Community

Cover image for 4 Bit ALU
Muhammad Hammad Yousaf
Muhammad Hammad Yousaf

Posted on

4 Bit ALU

Processor and its components

A processor consists of several components including a control unit, an arithmetic logic unit, registers, and some sort of CPU interconnection. All these components help organize and allow data processing by the computer

What is an ALU?

The arithmetic logic unit is the main functional component of a processor that performs all the data processing. It can perform arithmetic operations as well as logical operations. 
We'll try to build a very basic ALU that can perform data processing on 4 bits of data, using Logisim.

Design

We'll design an ALU that can perform four types of operations on two inputs each consisting of 4 bits. We can use a 2-bit op-code to represent the operation we want to perform.

Operations

  • 00 - Logical AND
  • 01 - Logical OR
  • 10 - Addition
  • 11 - Subtraction

Components

We'll divide our ALU into following smaller blocks.

  • AND block
  • OR block
  • Arithmetic block
  • 3-1 Multiplexer

Flags

We'll also have two output flags

  • Bit overflow - active when addition yields a result that can't be represented by a 4-bit output
  • Equal flag - active when two numbers (inputs) are equal
Let's get started!

Arithmetic Unit

We'll start from very basic circuits and then create an arithmetic unit that can perform addition and subtraction.

Full Adder
A full adder can add 2 single-bit numbers along with a carry and generate the sum and a carry out which can be passed to the next adder
Full Adder
Chip View

Full Adder
4 bit adder
Using full adder we can build a circuit which can add up to four bits

Four Bit Adder
Chip View

Four Bit Adder
Arithmetic Unit
An adder can be used to perform subtraction using the technique called 2's complement.

Arithmetic Unit
Chip View

Arithmetic Unit

Logical Unit

Logical units are fairly simple and they perform a logical operation on a single bit from each input.
OR Block

OR Block
Chip View

OR Block
AND Block

AND Block
Chip View

AND Block

Flags

Bit Overflow Flag
The flag is only active when the op-code is 10 (ADD) and the output can't be represented by a 4-bit number.

Bit Overflow Flag
Chip View

Bit Overflow Flag
Equal Flag
The flag is only active when the op-code is 11 (SUB) and both inputs are equal

Equal Flag
Chip View

Equal Flag

Multiplexer

We can generate a single output from multiple outputs from our different blocks based on our op-code. We can use a 3-1 multiplexer
2-1 MUX

2-1 MUX
Chip View

2-1 MUX
3-1 MUX

3-1 MUX
Chip View

3-1 MUX

ALU

Now, let's plug everything together

4 Bit ALU

Conclusion

Most modern ALUs can perform way many operations on high number of bits. We can upgrade our ALU to perform other operations as well. This is just a very basic representation of how we can create our circuit that may perform very basic operations.

Top comments (0)