Introduction of Arithmetic and Logic Unit
An Arithmetic and Logic Unit, or ALU for short, is a combinational logic circuit responsible for implementing multiple sets of arithmetic and logical operations in a computer.
Take a look at the object above, in the picture is the most famous ALU - Intel 74181, released in 1970, at that time it was the first complete ALU completely packaged in a single chip, which was an amazing project for people.
Today, let's build a simple ALU circuit with Boolean logic gates that performs the same function as the 74181.
Before building an ALU, we need to know that an ALU circuit contains 2 units, an arithmetic unit and a logic unit.
Let's start with the arithmetic unit, the arithmetic unit is responsible for all numerical operations in the computer, such as addition and subtraction, of course, it will also do some other simple things, such as adding 1 to a number, which is called incremental arithmetic.
In the arithmetic unit, we use AND, OR, NOT and XOR logic gates. In the simplest addition circuit, there are 2 binary inputs: A and B, and 1 is the output, which is the sum of the two binary numbers.
Assuming that both A and B have only one bit, either 0 or 1, the only possible combinations for the operation of A and B are the following four:
0+0=0
1+0=1
0+1=1
1+1=10
As a reminder, in binary, 1 stands for true and 0 stands for false, so the first three possibilities for this set of inputs and outputs have the same logical relationship as the XOR gate.
The fourth combination of inputs, obviously 1+1≠2, because there is no 2 in binary, so the result is 0, the 1 is rounded to the next digit, and the sum is binary "10", for the output of the XOR gate, it is only partially correct, that is, 1 plus 1, the output is 0. At this point, we just need an extra line to represent the rounding, that is This time, we just need an extra line to represent the rounding, i.e., the rounding is "true" only when the inputs are 1 and 1.
To solve the above problem, we can add the AND gate to the circuit, that is, when both inputs are "true", the output is "true", so that the composition of the "half-adder This makes a "half adder" circuit.
If you want to deal with cases larger than 1+1, you need a full adder. A full adder is more complicated than a half adder in that it has 3 bit inputs: A, B, and C, so the maximum possible inputs are 1+1+1, sum 1, and round 1, and therefore it needs two outputs, namely the rounding line and the summing line.
In fact, we can also use a half adder to realize the function of a full adder. First, we can use a half adder to add A and B, then input C into the second half adder, and finally, we can use an OR gate to check if the feed is true.
Now, we can make a circuit that adds two 8 Bits which are A and B. Look at the figure below:
We start adding from the first bit of A and B. The first bit is called A0 and B0, respectively, because there are only 2 numbers, so a half adder will do, and we will call the sum of the two of them Sum0. Considering that when A1 and B1 are added there may be a rounding up of the addition of A0 and B0, which would make it 3 numbers, so you have to use a full adder from the beginning of the addition of A1 and B1, and then so on, to take care of the 8 bit of the sum, which is called an "8-bit pulsed-feed adder".
Please note: A7 and B7 full adder has a "rounding" output, if the two of them have output rounding, on behalf of the digital A and B added, and more than 8 bits, which is called "overflow" (overflow). If you want to avoid overflow, you have to add more full adders, and then add 16 or 32 bits, which will make overflow more difficult to occur, but the disadvantage is that each time the bit to move forward a little time.
Simple ALUs don't have specialized circuits to handle multiplication and division, but instead use multiple additions to implement the multiplication operation, e.g., you can add 12 five times to implement 12 times 5.
Of course, don't worry about our current laptops and cell phones because they have better processors that can specialize in arithmetic units for multiplication.
We've talked a lot about the arithmetic unit, but now, let's talk about the other half of the ALU: the logic unit. The logic unit performs logical operations, like the AND, OR, and NOT operations discussed earlier, and of course it can also perform simple numerical tests, like checking the positive and negative of a number.
The diagram above shows the circuit to check if the output of the ALU is 0. A bunch of OR gates are used to check if one of the bits is 1. Even if only one Bit is 1, we can be sure that the number is not 0. Then a NOT gate is used to invert the number, so that the output is 1 only if the input number is 0.
At this point, we've gotten a high-level overview of the ALU, and even made a couple of the main components, such as the pulsed-in adder, although it's just a clever way of connecting a bunch of logic gates together. Let's go back to the ALU we talked about at the beginning, the Intel 74181, which only has a 4-bit input, whereas the one we just described has an 8-bit input, which is oh so much more than the 74181!
Although we did not make the ALU physical, but we should have had the overall concept of the ALU, its birth opened the door to a more powerful computer.
As ALU is used more and more in the market, engineers used a symbol that looks like a big "V" to represent it for the sake of convenience.
A 4-bit ALU requires a lot of logic gates, an 8-bit ALU requires logic gates must be more, we engineers certainly do not want to waste a lot of time here, then there is a way to facilitate the implementation of the ALU operation code required, which later have the opportunity to introduce to you in detail.
ALU in addition to output the results of calculations, but also a series of output flags (Flag), this flag represents a specific state of 1 bit (bit) output, for example, if we subtract two numbers, the result is 0, our zero test circuit will be set to zero flag True (1), which is very useful in determining whether the two numbers are equal.
Of course this flag bit can also be used to determine the size of the number and whether there is an overflow, etc. If the better the ALU used, it will have more flags, but the 3 flags just mentioned are the ones that ALUs will commonly use.
History of the development of arithmetic logic units
In computers, arithmetic logic units (ALUs) are digital circuits that specialize in performing arithmetic and logic operations.ALUs are the most important part of a computer's central processor, and even the smallest microprocessors contain ALUs for counting functions.
Modern CPU and GPU processors contain powerful and complex ALUs; a single component may also contain an ALU.
The concept of the ALU was introduced in 1945 by mathematician von Neumann in a report describing the basic components of a new type of computer called the EDVAC.
Early Developments
In 1946, von Neumann worked with colleagues to design a computer for the Institute for Advanced Study (IAS) in Princeton. The IAS computer then became the prototype for what would become the computer. In his dissertation, Von Neumann referred to what he
believed were the necessary components of a computer, which included the ALU. Von Neumann wrote that the ALU was a necessary component of a computer because it had been determined that a computer must perform basic mathematical operations, including
addition, subtraction, multiplication, and division. He then believed that "the [computer] should contain components specialized in accomplishing such operations."
Digital Systems
The ALU must use the same format for numerical processing as the rest of the digital circuit. For modern processors, values are always represented using the binary complement. Early computers used a variety of number systems, including inverse codes, symbolic
numeric codes, and even decimal codes with ten tubes for each bit. The ALUs corresponding to each of these number systems had different designs, and this has influenced the current preference for binary complement codes, which simplify ALU addition and
subtraction operations. A simple 2-bit ALU capable of performing with or without and addition operations.
Feasibility Analysis
The vast majority of computer instructions are executed by the ALU.The ALU takes data from registers. The data is processed and the result of the operation is stored in the ALU output register. Other components are responsible for transferring data between registers
and memory. The control unit controls the ALU by using control circuits to tell the ALU what operation to perform.
Simple Arithmetic
Most ALUs can perform the following operations.
Integer arithmetic operations (addition, subtraction, and sometimes multiplication and division, but at a higher cost).
Bitwise logic operations (and, or, not, different or).
Shift operations (shifting or floating a word to the left or right by a specific bit, without sign extension); a shift can be thought of as multiplying by 2 or dividing by 2.
Complex Arithmetic
Engineers can design ALUs that can do any operation, no matter how complex; the problem is that the more complex the operation, the more expensive the ALU, the more space it takes up in the processor, and the more power it consumes. Therefore, engineers often
calculate a compromise to provide the processor (or other circuits) to make its operations a high-speed ALU, but at the same time to avoid the ALU design is too complex and expensive. Imagine that you need to calculate the square root of a number, and the digital
engineer will evaluate the following options to accomplish this operation.
Design an extremely complex ALU that can do the square root of any number in one step. This is called a single-clock-pulse calculation.
Design a very complex ALU that can do the square root of a number in several steps. However, here's the trick, the intermediate result goes through a series of circuits, like a production line in a factory. This even allows the ALU to accept new numbers before
completing the previous operation. This allows the ALU to generate numbers at the same rate as a single clock pulse, although there is an initial delay in the output from the ALU. This is known as a computational pipeline.
Design a complex ALU that is capable of computing the square root of a number in several steps. This is known as interactive computation and often relies on complex control units with embedded microcode.
Design a simple ALU in a processor that removes an expensive processor dedicated to this operation, and then choose one of the three options above. This is called a coprocessor.
Programmers are told that they don't have a coprocessor or an emulation device, so they have to write their own algorithm to compute the square root in software. This is done by a software library.
Emulate the coprocessor, that is, whenever a program wants to do a square root calculation, have the processor check to see if there is currently a coprocessor. If there is one, it uses it to perform the computation, if not, it interrupts the program process and calls the
operating system to perform the square root computation through a software algorithm. This is called software emulation.
The options given above are organized from fastest and most expensive to slowest and most economical. Thus, while even the simplest computers can compute the most complex formulas, the simplest computers often take a lot of time and several steps to do so.
Powerful processors such as the Intel Core and AMD64 series use option #1 for some simple operations, option #2 for the most common complex operations, and option #3 for extremely complex operations. This presupposes the ability to construct very complex
ALUs in the processor.
Inputs and Outputs
The inputs to the ALU are the data to be operated on (called operands) and the instruction code from the control unit that indicates which operation is to be performed. Its outputs are the results of the operations. In many designs the ALU also receives or issues input
or output condition codes to (or from) the status register. These codes are used to indicate conditions such as rounding or borrowing, overflow, division by zero, etc.
ALU and FPU
The floating-point unit also performs arithmetic operations on two values, but such operations have been represented as floating-point numbers, which is much more complex than the complementary representation generally used in the ALU. In order to perform
such operations, several complex circuits are embedded in the FPU, including some internal ALUs. Engineers generally think of ALUs as circuits that deal with arithmetic operations on integer types (such as complement and BCD codes), while circuits that perform
calculations on more complex formats (such as floating-point and complex numbers) have a more matching designation.
Characteristics of the Arithmetic Logic Unit
The ALU is used to perform arithmetic and logical operations in a computer's instruction set.
In some processors, the ALU is divided into two parts, the arithmetic unit (AU) and the logic unit (LU). Some processors contain more than one AU, e.g., one for fixed-point operations and another for floating-point operations. (In personal computers, floating-point
operations are sometimes performed by a floating-point unit called a digital coprocessor.)
In general, ALUs have direct read-in and read-out access to the processor controller, memory, and input and output devices. Inputs and outputs are performed over a bus. An input instruction consists of an instruction word, sometimes called a machine instruction
word, which includes an opcode, single or multiple operands, and sometimes a format code; the opcode instructs the ALU machine what operation is to be performed and how many operands are to be executed in that operation. For example, two operands can be
compared or an addition operation can be performed. The format code can be combined with the opcode to inform whether this is a fixed-point or floating-point instruction; the output consists of the result stored in a storage register and a setting indicating whether
the operation was successful. If the operation fails, the corresponding status is displayed in the machine status word .
Typically, the storage locations for input operands, operands, sums, and conversion results are in the ALU. In the arithmetic unit, multiplication and division operations are obtained by a series of addition and subtraction operations. There are various ways to represent
negative numbers in machine code.
In the logic unit, one of the 16 possible logical operations is performed at a time.
The design of the ALU is a critical part of processor design. Research continues to be done to increase the processing speed of instructions.