Nepedia
Back to Discover
Advanced Reader
💻

Arithmetic logic unit

technology Maturity 7-9 Next article →

An arithmetic logic unit, or ALU, is a fundamental digital circuit in modern computing.

ALU block
ALU block

It is a combinational circuit designed to perform arithmetic and bitwise operations on integer binary numbers. This makes it a primary building block for many types of processors. You will find ALUs inside central processing units (CPUs) and graphics processing units (GPUs). While an ALU handles integers, other units called floating-point units (FPUs) are used for different types of numbers. The ALU is essentially the mathematical engine of the computer.

To function, the ALU requires specific inputs to determine its task. These inputs include operands, which are the actual data values being processed. The ALU also receives an opcode, or operation code. The opcode is an enumerated value that tells the ALU which specific operation to perform. The size of the opcode bus determines how many different operations the unit can handle. For example, a four-bit opcode allows for up to sixteen distinct operations.

74181aluschematic
74181aluschematic

The final result of the operation is then sent to an output bus.

ALU data paths
ALU data paths

The physical movement of data happens through electrical conductors called nets. These nets form data buses, which are groups of signals that carry binary integers. A standard ALU typically uses three parallel data buses: two for the input operands, known as A and B, and one for the result, known as Y. Usually, the width of these buses matches the native word size of the processor. The ALU is a combinational logic circuit, meaning its outputs change in response to input changes. There is a brief period called propagation delay, which is the time required for signals to move through the circuitry. To manage this, external circuitry uses a clock signal to ensure signals are stable before they are sampled.

An ALU supports a wide variety of arithmetic functions. It can perform basic addition of two operands, A and B. It can also perform "add with carry," where a carry-in bit from a previous operation is included in the sum. Subtraction is another core function, which can also act as a way to compare the magnitude of two numbers. The ALU can also perform two's complement to find the negative of a number. Other arithmetic tasks include incrementing a value by one or decrementing it by one. These operations allow the processor to handle almost any basic mathematical requirement.

Beyond math, the ALU performs bitwise logical operations. These include AND, OR, and exclusive-OR (XOR) operations. These functions allow the computer to test specific bits within a number. The ALU can also perform bit shift operations. In a shift, the bits in an operand move left or right. Simple ALUs shift by only one bit at a time. However, more complex units use a barrel shifter to move an arbitrary number of bits in a single operation.

Rotate left logically
Rotate left logically

Different types of shifts exist, such as arithmetic shifts, logical shifts, and rotations. In a rotation, the bits are treated like a circular buffer where the ends meet.

AluStatusRegister
AluStatusRegister

When an operation finishes, the ALU provides supplemental information through status outputs. These signals describe the nature of the result. A carry-out signal indicates a carry from addition or a borrow from subtraction. A zero signal indicates the result is entirely composed of logic zeros. The negative signal shows if a result is negative, while the overflow signal indicates a result has exceeded the numeric range of the output bus. Parity signals indicate if there is an even or odd number of bits set to one. These status bits are often stored in a status register, also called a condition code register, to help the computer make decisions during conditional branching.

One of the most important uses of these status signals is in multiple-precision arithmetic. This is an algorithm used when a number is larger than the ALU's word size. For instance, an 8-bit ALU can process a 24-bit integer by breaking it into three 8-bit fragments. The ALU operates on the least-significant fragments first. It then uses the carry-out bit from that operation as a carry-in for the next fragment. By repeating this process for every piece, the ALU can successfully calculate much larger numbers than its physical size would normally allow. This connection between small circuits and large-scale math is a key part of how computers function.

729 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (11)
File:ALU block.svg
ALU block.svg
File:74181aluschematic.svg
74181aluschematic.svg
File:Rotate left logically.svg
Rotate left logically.svg
File:Rotate right logically.svg
Rotate right logically.svg
File:Rotate right through carry.svg
Rotate right through carry.svg
File:Rotate left through carry.svg
Rotate left through carry.svg
File:Rotate left.svg
Rotate left.svg
File:Rotate right.svg
Rotate right.svg
File:Rotate right arithmetically.svg
Rotate right arithmetically.svg
File:AluStatusRegister.svg
AluStatusRegister.svg
File:ALU data paths.svg
ALU data paths.svg
More to explore

🔗 What's this?

Concepts mentioned in this article

🔬 Go deeper

More advanced topics to explore

🪜 Step back

Simpler topics to build understanding

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.