An arithmetic logic unit, or ALU, combines operations such as addition, subtraction, AND and OR behind a selection input. Its output is the result of the selected operation. Flags such as zero, carry and signed overflow provide additional information under a specified convention.

Worked example

Imagine a four-bit ALU where opcode 00 selects addition, 01 selects subtraction, 10 selects AND and 11 selects OR. With A = 1010 and B = 1100, opcode 10 produces 1000, while opcode 11 produces 1110.

What to watch for

An opcode assignment is a design choice, not a universal standard. Define whether each flag is meaningful for every operation, especially logical operations.

Try it yourself

For the example ALU, what does opcode 00 produce for A = 0011 and B = 0010?

Answer: Addition gives 0101, or decimal 5. The zero flag is clear because the result is nonzero.

How to study this topic

State the operand width and signedness first. Work out a decimal answer, then compare it with the binary result. Keep result bits, carry, borrow and signed overflow distinct when interpreting the circuit's output.

Explore related programmes

These recorded programmes are upcoming. This article is general educational content, not a syllabus or course sample.

Digital Electronics