1. Connect sets: Representing and storing numbers is an important function of a computer, but the real goal of a computer is to compute meaningful numbers.
Add two numbers together. These operations are handled by the computer's arithmetic logic unit, collectively known as the ALU.Copy the code
2. ALU
- Is the mathematical brain of the computer;
- It’s the part of the computer that does the calculations, and basically everything else uses it;
- The most famous ALU, the Intel 74181 (can only handle 4-bit input, uses about 70 logic gates, but can’t perform multiplication and division). When it was released in 1970, it was the first complete ALU packaged on a single chip;
- ALU has two units, one arithmetic unit and one logic unit.
3. Arithmetic unit
-
Responsible for all numerical operations in the computer, such as addition and subtraction;
-
In binary, 1 is the same as true and 0 is the same as false;
-
Half adder: AND gate, output is true only if both are true, add this to the circuit, called “half adder”;
-
Full adder: If we want to handle more than 1+1 operations, we need “full adder”;
-
8 bit adder (1 half adder, 7 full adder);
-
The concept of overflow: the sum of two numbers is too large for the number of digits used to represent, which results in errors and unexpected results;
- Example: Pac-Man uses 8 bits to store the current number of levels, and if you reach level 256, the ALU will overflow
-
Multiplication and division: Simple ALU has no dedicated circuit to handle multiplication and division. So for multiplication, ALU uses multiple addition implementations.
4. Logical unit
- A circuit that detects whether the number is 0;
- ALU is abstracted as a V symbol;
- Flag: contains only one bit, indicating a specific status.
- Overflow flag;