CS Crash Course: #5 How Computers Calculate - the ALU

Intro

- Representing and storing numbers is an important funtion of a computer, but the real goal is computation, or manipulating numbers in a structured and purposeful way, like adding two numbers together. These operations are handled by a computer's Arithmetic and Logic Unit, ALU, which is the mathematical brain of a computer.

- The most famous ALU ever was the Intel 74181. When it was released in 1970, the first complete ALU that ift entirely inside of a single chip, which was a huge engineering feat at the time.  

ALU is two units in one, an arithmetic unit and a logic unit 

- Arithmetic unit is responsible for handling all numerical operations in a computer, like addition and subtraction. Also, it does other simple things like increment. 

- We can build our components out of logic gates, AND, OR, NOT, and XOR gates.

- The simplest adding circuit that we can build takes two binary digits, and adds them together. We have two inputs, A and B, and one output, which is the sum of those two digits. A, B and the output are all single bits. 

- There are only 4 input combinations. If A and B are both 1, the output is 10. Now the output of our XOR gate is partially correct, 1 plus 1, output 0. But, we need an extra output wire for that carry bit. The carry bit is only "true" when the inputs are 1 and 1, because that's the only time when the result is bigger than 1 bit can store. Conveniently we have a gate for that. An AND gate, which is only true when both inputs are true, so we'll add that to our circuit too. 

- Half adder: as its own component, with two inputs -- bits A and B -- and two outputs, the sum and the carry bits. 

- If you want to add more than 1 + 1(Ex. 101 + 101), we're gonna need a "Full Adder." That half-adder left us with a carry bit as output. That means that when we move on to the next column in a multi-column addition, and every column after that, we are gonna have to add three bits together, no two. 

- We can build a full adder using half adders. To do this, we use a half adder to add A plus B just like before, but then feed that result and input C into a second half adder. Lastly, we need a OR gate to check if either one of the carry bits was true. 

- In general, an overflow occurs when the result of an addition is too large to be represented by the number of bits you are using. This can usually cause errors and unexpected behavior. 

- If we wanna avoid overflows, we can extend our circuit with more full adders, allowing us add 16 or 32 bit numbers. This makes overflows less likely to happen, but at the expense of more gates. An additional downside is that it takes a littel bit of time for each of the carries to ripple forward. 

- Electrons move pretty fast, so we're talking about billions of a second, but that's enough to make a difference in today's fast computers. For this reason, modern computers use a slightly different adding circuit called a "carry-look-ahead" adder. which is faster, but ultimately does exactly the same thing -- adds binary numbers. 

- The reason why there're no multiply and divide operations is because simple ALUs don't have a circuit for this, and instead just perform a series of additions. For instance, 12 * 5 is the same thing as adding 12 to itself 5 times. This is how many simple processors like TV remote and microwave do multiplication. However, facier processors like those in your laptop or smartphone have arithmetic units with dedicated circuits for multiplication. The circuit is more complicated than addition, but it just taks a lot more logic gates, which is why less expensive processors do not have this feature. 

Tukareta, watch the video whose part of logic unit begins 7:30. Bye

この記事が気に入ったらサポートをしてみませんか?