Computer Arithmetic

the arithmetic logic unit (ALU)

/ ALU = AY-ell-you /

Imagine the part of a calculator that actually does the figuring once you have punched in the numbers and pressed a key. The arithmetic logic unit, or ALU, is exactly that block inside the processor: a lump of combinational logic that takes two numbers in and produces one result out, where a few control wires choose which operation to perform. It does not remember anything and it has no notion of time of its own; it is a pure function of its inputs, the way a vending machine gives you the same snack every time you press the same button.

Concretely an ALU has two data inputs (each usually a full word, say 32 or 64 bits wide), a small operation-select input (a handful of bits that pick add, subtract, AND, OR, compare, and so on), one data output of the same width, and a few one-bit status outputs called flags. Inside, it is built from the adders and logic gates of the digital-logic field: a wide adder for add and subtract, banks of AND and OR gates for the bitwise operations, and a multiplexer that lets the operation-select bits steer the right result to the output. Press the add code and the adder's sum reaches the output; press the AND code and the gate bank's result does instead.

The ALU is the calculating heart of the datapath, but it is deliberately humble: it does arithmetic and logic on two operands and nothing more. It does not fetch instructions, does not decide what to compute next, and usually does not even do multiplication or division on its own (those need extra hardware or many passes). Keeping the ALU simple and fast matters because almost every instruction touches it, so its delay sits on the processor's critical path and helps set how high the clock can run.

Op-select 0b0010 means add: feed in 5 and 3, the internal adder produces 8, the multiplexer routes 8 to the output, and the zero flag stays 0 because the result is non-zero. Switch op-select to 0b0110 (subtract) and the same two inputs give 5 minus 3 = 2.

One block, many operations: the op-select bits choose which internal result reaches the output.

The ALU is combinational and has no memory of its own; the registers that feed and catch its values live elsewhere in the datapath. Multiply and divide are usually separate, slower units, not part of the basic ALU.

Also called
ALU算術邏輯單元