How Computers Calculate - the ALU: Crash Course Computer Science #5

How Computers Calculate - the ALU: Crash Course Computer Science #5

Introduction to ALU and Binary Addition

In this section, Carrie Ann introduces the concept of Arithmetic and Logic Unit (ALU) and its importance in computer computation. She also mentions the Intel 74181, a famous ALU from 1970.

The Role of ALU in Computer Computation

  • The ALU is responsible for performing mathematical operations and logical manipulations on numbers.
  • It is considered the mathematical brain of a computer.
  • Understanding the design and function of an ALU is crucial to understanding modern computers.

Building an ALU Circuit

  • An ALU can be built using logic gates such as AND, OR, NOT, and XOR gates.
  • The simplest adding circuit, called a half adder, takes two binary digits as inputs and produces their sum as output.
  • A full adder is needed to handle multi-column addition by adding three bits together: A, B, and a carry bit.

Abstraction Levels

  • Components like half adders and full adders can be abstracted into their own components for easier circuit design.
  • This allows for higher levels of abstraction in building complex circuits.

Understanding Arithmetic Unit

In this section, Carrie Ann explains the role of the arithmetic unit within an ALU. She focuses on addition as a fundamental operation performed by the arithmetic unit.

Arithmetic Unit Functionality

  • The arithmetic unit handles numerical operations such as addition and subtraction.
  • It can also perform other simple operations like incrementing a number.

Focus on Addition

  • Adding two numbers together is a key operation performed by the arithmetic unit.
  • Binary addition follows boolean logic rules using XOR gates for most input combinations.
  • Special cases like 1 + 1 require additional logic to handle carry bits.

Full Adder Construction

In this section, Carrie Ann explains how to construct a full adder using half adders and additional logic gates.

Building a Full Adder

  • A full adder takes three inputs: A, B, and a carry bit.
  • It produces two outputs: the sum of the inputs and a carry bit for the next column.
  • The construction involves using two half adders and an OR gate to check for any carry bits.

Circuit Construction for Multi-Bit Addition

In this section, Carrie Ann demonstrates how to build a circuit that can perform addition on two 8-bit numbers.

Multi-Bit Addition Circuit

  • The circuit starts with adding the least significant bits (A0 and B0) using a half adder.
  • Carry bits from previous additions are considered in subsequent full adders.
  • The process continues until all 8 bits have been added.

This summary covers only a portion of the transcript.

New Section

This section discusses the concept of overflow in binary addition and its implications. It also mentions the use of a carry-look-ahead adder for faster addition.

Overflow in Binary Addition

  • If there is a carry into the 9th bit, it means the sum of the two numbers is too large to fit into 8-bits. This is called an overflow.
  • An overflow occurs when the result of an addition is too large to be represented by the number of bits being used.
  • Overflows can cause errors and unexpected behavior.

Example: PacMan Game

  • The original PacMan arcade game used 8 bits to keep track of levels.
  • When players reached level 256, which was beyond the largest number storable in 8 bits, an overflow occurred in the ALU.
  • This caused errors and glitches, making the level unbeatable.

Extending Circuit for Avoiding Overflows

  • To avoid overflows, circuits can be extended with more full adders to allow adding larger numbers (e.g., 16 or 32-bit).
  • Adding more full adders reduces the likelihood of overflows but increases gate count.
  • Ripple carry propagation introduces a small delay as each carry has to ripple forward.

Carry-Look-Ahead Adder

  • Modern computers use a faster adding circuit called a "carry-look-ahead" adder.
  • Carry-Look-Ahead adders reduce propagation delays by generating carries independently before they are needed.

New Section

This section explains that arithmetic units in ALUs support various math operations built from individual logic gates. It also discusses how multiplication and division are performed using repeated additions.

Arithmetic Operations in ALU

  • ALU's arithmetic unit supports various math operations such as addition, subtraction, AND, OR, NOT, etc.
  • These operations are built from individual logic gates.

Multiplication and Division

  • Simple ALUs do not have dedicated circuits for multiplication and division.
  • Multiplication is performed by adding a number to itself multiple times (e.g., multiplying 12 by 5 requires 5 passes through the ALU).
  • Fancier processors have dedicated circuits for multiplication, which involve more complex logic gates.

New Section

This section focuses on the Logic Unit in an ALU that performs logical operations like AND, OR, NOT. It also discusses how numerical tests such as checking if a number is negative are performed.

Logic Unit in ALU

  • The Logic Unit in an ALU performs logical operations like AND, OR, and NOT.
  • It also performs numerical tests such as checking if a number is negative.

Testing for Zero Output

  • A circuit can be used to test if the output of the ALU is zero.
  • The circuit uses OR gates to check if any of the bits are 1. If at least one bit is 1, the number cannot be zero.
  • A final NOT gate flips this input so that the output is only 1 when the input number is 0.

New Section

This section mentions the Intel 74181 ALU and its limitations compared to building an 8-bit ALU from scratch. It also introduces abstraction in representing complex circuits with symbols.

Intel 74181 ALU

  • The Intel 74181 was an early ALU that could handle only 4-bit inputs and had limitations like no support for multiplication or division.
  • Building an 8-bit ALU from scratch using basic components can surpass the capabilities of famous commercial ones like the Intel 74181.

Abstraction with Symbols

  • Engineers introduced a special symbol, resembling a big 'V', to represent complex ALU circuits.
  • This symbol provides a higher level of abstraction, hiding the complexity of the underlying circuitry.

New Section

This section explains the inputs and outputs of an 8-bit ALU, including operation codes and flags. It also mentions how flags can be used for various purposes.

Inputs and Outputs of an 8-bit ALU

  • An 8-bit ALU has two inputs (A and B) with 8 bits each.
  • A 4-bit operation code is used to specify the desired operation (e.g., addition or subtraction).
  • The output is an 8-bit result of the specified operation on inputs A and B.

Flags in ALUs

  • ALUs also output flags, which are 1-bit outputs representing specific states or statuses.
  • Commonly used flags include the Zero Flag (indicating if the result is zero), Negative Flag (indicating if the result is negative), and Overflow Flag (indicating if there was an overflow during addition).
  • Flags can be utilized for various purposes, such as equality testing or determining if one number is smaller than another.

New Section

This section concludes by summarizing how computers perform basic mathematical operations digitally using ALUs.

Basic Mathematical Operations in Computers

  • Computers perform basic mathematical operations digitally using Arithmetic Logic Units (ALUs).
  • ALUs support arithmetic operations like addition, subtraction, logical operations like AND, OR, NOT, as well as numerical tests.
  • Multiplication and division are performed through repeated additions or dedicated circuits in more advanced processors.
Playlists: Computer Science
Video description

Today we're going to talk about a fundamental part of all modern computers. The thing that basically everything else uses - the Arithmetic and Logic Unit (or the ALU). The ALU may not have to most exciting name, but it is the mathematical brain of a computer and is responsible for all the calculations your computer does! And it's actually not that complicated. So today we're going to use the binary and logic gates we learned in previous episodes to build one from scratch, and then we'll use our newly minted ALU when we construct the heart of a computer, the CPU, in episode 7. *CORRECTION* We got our wires crossed with the Intel 4004, which we discuss later. The 74181 was introduced by Texas Instruments in 1970 but appeared in technical manuals around 1969. The design of the 74181, like most of the 74xx/74xxx series, was an open design which was manufactured by many other companies - Fairchild was one such manufacturer. They produced a chip, the Fairchild 9341, which was pin-for-pin compatible with the 74181. Fairchild was the first to prototype an ALU, building the Fairchild 4711 in 1968 - a one-off device not optimized for scale manufacturing. In 1969, Signetics came out with the 8260, which they marketed in a very limited sense (it was attached, AFAICT, to one particular computer, the Data General SUPERNOVA). TI follows afterwards (March 1970) with the 74181, coupled with the 9341 from Fairchild. The 74181 became the standard number for this part, and was available from many manufacturers (back in those days, chip makers cross-licensed designs all over the place in order to provide assurance that their part could be sourced from multiple manufacturers). Produced in collaboration with PBS Digital Studios: http://youtube.com/pbsdigitalstudios The Latest from PBS Digital Studios: https://www.youtube.com/playlist?list... We’ve got merch! https://store.dftba.com/collections/crashcourse Want to know more about Carrie Anne? https://about.me/carrieannephilbin Want to find Crash Course elsewhere on the internet? Facebook - http://www.facebook.com/YouTubeCrashC... Twitter - http://www.twitter.com/TheCrashCourse Tumblr - http://thecrashcourse.tumblr.com Support Crash Course on Patreon: http://patreon.com/crashcourse CC Kids: http://www.youtube.com/crashcoursekids Want to find Crash Course elsewhere on the internet? Facebook - http://www.facebook.com/YouTubeCrashCourse Twitter - http://www.twitter.com/TheCrashCourse Tumblr - http://thecrashcourse.tumblr.com Support Crash Course on Patreon: http://patreon.com/crashcourse CC Kids: http://www.youtube.com/crashcoursekids