YouTube2Text

The Central Processing Unit (CPU): Crash Course Computer Science #7 — Transcript

by CrashCourse · 2,115 words · 172 segments · language en · Watch on YouTube

Full transcript

  1. 0:03Hi, I’m Carrie Anne, this is Crash Course Computer Science, and today, we’re talking about processors.
  2. 0:07Just a warning though - this is probably the most complicated episode in the series.
  3. 0:11So once you get this, you’re golden.
  4. 0:12We’ve already made a Arithmetic and Logic Unit, which takes in binary numbers and performs
  5. 0:16calculations, and we’ve made two types of computer memory: Registers -- small, linear
  6. 0:21chunks of memory, useful for storing a single value -- and then we scaled up, and made some
  7. 0:26RAM, a larger bank of memory that can store a lot of numbers located at different addresses.
  8. 0:30Now it’s time to put it all together and build ourselves the heart of any computer,
  9. 0:34but without any of the emotional baggage that comes with human hearts.
  10. 0:37For computers, this is the Central Processing Unit, most commonly called the CPU.
  11. 0:42INTRO
  12. 0:51A CPU’s job is to execute programs.
  13. 0:53Programs, like Microsoft Office, Safari, or your beloved copy of Half Life: 2, are made
  14. 0:57up of a series of individual operations, called instructions, because they “instruct”
  15. 1:02the computer what to do.
  16. 1:03If these are mathematical instructions, like add or subtract, the CPU will configure its
  17. 1:07ALU to do the mathematical operation.
  18. 1:10Or it might be a memory instruction, in which case the CPU will talk with memory
  19. 1:14to read and write values.
  20. 1:15There are a lot of parts in a CPU, so we’re going to lay it out piece by piece, building
  21. 1:19up as we go.
  22. 1:20We’ll focus on functional blocks, rather than showing every single wire.
  23. 1:23When we do connect two components with a line, this is an abstraction for all of the necessary wires.
  24. 1:28This high level view is called the microarchitecture.
  25. 1:30OK, first, we’re going to need some memory.
  26. 1:32Lets drop in the RAM module we created last episode.
  27. 1:35To keep things simple, we’ll assume it only has 16 memory locations, each containing 8 bits.
  28. 1:40Let’s also give our processor four, 8-bit memory registers, labeled A, B, C and D which
  29. 1:45will be used to temporarily store and manipulate values.
  30. 1:48We already know that data can be stored in memory as binary values
  31. 1:51and programs can be stored in memory too.
  32. 1:52We can assign an ID to each instruction supported by our CPU.
  33. 1:56In our hypothetical example, we use the first four bits to store the “operation code”,
  34. 2:00or opcode for short.
  35. 2:02The final four bits specify where the data for that operation should come from -
  36. 2:06this could be registers or an address in memory.
  37. 2:08We also need two more registers to complete our CPU.
  38. 2:11First, we need a register to keep track of where we are in a program.
  39. 2:14For this, we use an instruction address register, which as the name suggests, stores the memory
  40. 2:19address of the current instruction.
  41. 2:20And then we need the other register to store the current instruction, which we’ll call the instruction register.
  42. 2:26When we first boot up our computer, all of our registers start at 0.
  43. 2:30As an example, we’ve initialized our RAM with a simple computer program that we’ll to through today.
  44. 2:35The first phase of a CPU’s operation is called the fetch phase.
  45. 2:38This is where we retrieve our first instruction.
  46. 2:41First, we wire our Instruction Address Register to our RAM module.
  47. 2:44The register’s value is 0, so the RAM returns whatever value is stored in address 0.
  48. 2:49In this case, 0010 1110.
  49. 2:52Then this value is copied into our instruction register.
  50. 2:55Now that we’ve fetched an instruction from memory, we need to figure out what that instruction is
  51. 2:59so we can execute it.
  52. 3:00That is run it.
  53. 3:01Not kill it.
  54. 3:02This is called the decode phase.
  55. 3:04In this case the opcode, which is the first four bits, is: 0010.
  56. 3:08This opcode corresponds to the “LOAD A” instruction, which loads a value from RAM
  57. 3:13into Register A.
  58. 3:14The RAM address is the last four bits of our instruction which are 1110, or 14 in decimal.
  59. 3:19Next, instructions are decoded and interpreted by a Control Unit.
  60. 3:23Like everything else we’ve built, it too is made out of logic gates.
  61. 3:26For example, to recognize a LOAD A instruction, we need a circuit that checks if the opcode
  62. 3:31matches 0010 which we can do with a handful of logic gates.
  63. 3:35Now that we know what instruction we’re dealing with, we can go ahead and perform
  64. 3:38that instruction which is the beginning of the execute phase!
  65. 3:41Using the output of our LOAD_A checking circuit, we can turn on the RAM’s read enable line
  66. 3:45and send in address 14.
  67. 3:47The RAM retrieves the value at that address, which is 00000011, or 3 in decimal.
  68. 3:53Now, because this is a LOAD_A instruction, we want that value to only be saved into Register A
  69. 3:58and not any of the other registers.
  70. 3:59So if we connect the RAM’s data wires to our four data registers, we can use our LOAD_A
  71. 4:04check circuit to enable the write enable only for Register A.
  72. 4:07And there you have it -- we’ve successfully loaded the value at RAM address 14 into Register A.
  73. 4:12We’ve completed the instruction, so we can turn all of our wires off, and we’’re
  74. 4:16ready to fetch the next instruction in memory.
  75. 4:18To do this, we increment the Instruction Address Register by 1 which completes the execute phase.
  76. 4:23LOAD_A is just one of several possible instructions that our CPU can execute.
  77. 4:28Different instructions are decoded by different logic circuits, which configure the CPU’s
  78. 4:32components to perform that action.
  79. 4:34Looking at all those individual decode circuits is too much detail, so since we looked at one example,
  80. 4:38we’re going to go head and package them all up as a single Control Unit to keep things simple.
  81. 4:43That’s right a new level of abstraction.
  82. 4:51The Control Unit is comparable to the conductor of an orchestra, directing all of the different
  83. 4:55parts of the CPU.
  84. 4:57Having completed one full fetch/decode/execute cycle, we’re ready to start all over again,
  85. 5:02beginning with the fetch phase.
  86. 5:03The Instruction Address Register now has the value 1 in it, so the RAM gives us the value
  87. 5:07stored at address 1, which is 0001 1111.
  88. 5:12On to the decode phase!
  89. 5:130001 is the “LOAD B” instruction, which moves a value from RAM into Register B.
  90. 5:20The memory location this time is 1111, which is 15 in decimal.
  91. 5:24Now to the execute phase!
  92. 5:26The Control Unit configures the RAM to read address 15 and configures Register B to receive the data.
  93. 5:31Bingo, we just saved the value 00001110, or the number 14 in decimal, into Register B.
  94. 5:38Last thing to do is increment our instruction address register by 1, and we’re done with another cycle.
  95. 5:43Our next instruction is a bit different.
  96. 5:45Let’s fetch it.
  97. 5:461000 01 00.
  98. 5:49That opcode 1000 is an ADD instruction.
  99. 5:53Instead of an 4-bit RAM address, this instruction uses two sets of 2 bits.
  100. 5:57Remember that 2 bits can encode 4 values, so 2 bits is enough to select any one of our 4 registers.
  101. 6:02The first set of 2 bits is 01, which in this case corresponds to Register B, and 00, which is Register A.
  102. 6:09So “1000 01 00” is the instruction for adding the value in Register B into the value in register A.
  103. 6:17So to execute this instruction, we need to integrate the ALU we made in Episode 5 into our CPU.
  104. 6:23The Control Unit is responsible for selecting the right registers to pass in as inputs,
  105. 6:27and configuring the ALU to perform the right operation.
  106. 6:30For this ADD instruction, the Control Unit enables Register B and feeds its value into
  107. 6:34the first input of the ALU.
  108. 6:36It also enables Register A and feeds it into the second ALU input.
  109. 6:40As we already discussed, the ALU itself can perform several different operations, so the
  110. 6:45Control Unit must configure it to perform an ADD operation by passing in the ADD opcode.
  111. 6:50Finally, the output should be saved into Register A. But it can’t be written directly
  112. 6:54because the new value would ripple back into the ALU and then keep adding to itself.
  113. 6:58So the Control Unit uses an internal register to temporarily save the output, turn off the
  114. 7:03ALU, and then write the value into the proper destination register.
  115. 7:07In this case, our inputs were 3 and 14, and so the sum is 17, or 00010001 in binary,
  116. 7:16which is now sitting in Register A. As before, the last thing to do is increment our instruction
  117. 7:20address by 1, and another cycle is complete.
  118. 7:23Okay, so let’s fetch one last instruction: 01001101.
  119. 7:29When we decode it we see that 0100 is a STORE_A instruction, with a RAM address of 13.
  120. 7:35As usual, we pass the address to the RAM module, but instead of read-enabling the memory, we write-enable it.
  121. 7:40At the same time, we read-enable Register A. This allows us to use the data line to
  122. 7:45pass in the value stored in register A.
  123. 7:47Congrats, we just ran our first computer program!
  124. 7:50It loaded two values from memory, added them together, and then saved that sum back into memory.
  125. 7:55Of course, by me talking you through the individual steps, I was manually transitioning the CPU
  126. 8:00through its fetch, decode and execute phases.
  127. 8:03But there isn’t a mini Carrie Anne inside of every computer.
  128. 8:06So the responsibility of keeping the CPU ticking along falls to a component called the clock.
  129. 8:10As it’s name suggests, the clock triggers an electrical signal at a precise and regular interval.
  130. 8:15Its signal is used by the Control Unit to advance the internal operation of the CPU,
  131. 8:19keeping everything in lock-step - like the dude on a Roman galley drumming rhythmically
  132. 8:23at the front, keeping all the rowers synchronized... or a metronome.
  133. 8:27Of course you can’t go too fast, because even electricity takes some time to travel
  134. 8:31down wires and for the signal to settle.
  135. 8:33The speed at which a CPU can carry out each step of the fetch-decode-execute cycle is called its Clock Speed.
  136. 8:39This speed is measured in Hertz - a unit of frequency.
  137. 8:42One Hertz means one cycle per second.
  138. 8:45Given that it took me about 6 minutes to talk you through 4 instructions -- LOAD, LOAD,
  139. 8:49ADD and STORE -- that means I have an effective clock speed of roughly .03 Hertz.
  140. 8:53Admittedly, I’m not a great computer but even someone handy with math
  141. 8:57might only be able to do one calculation in their head every second or 1 Hertz.
  142. 9:01The very first, single-chip CPU was the Intel 4004, a 4-bit CPU released in 1971.
  143. 9:08It’s microarchitecture is actually pretty similar to our example CPU.
  144. 9:12Despite being the first processor of its kind, it had a mind-blowing clock speed of 740 Kilohertz
  145. 9:18-- that’s 740 thousand cycles per second.
  146. 9:22You might think that’s fast, but it’s nothing compared to the processors that we use today.
  147. 9:26One megahertz is one million clock cycles per second, and the computer or even phone
  148. 9:30that you are watching this video on right now is no doubt a few gigahertz -- that's
  149. 9:34BILLIONs of CPU cycles every… single... second.
  150. 9:38Also, you may have heard of people overclocking their computers.
  151. 9:41This is when you modify the clock to speed up the tempo of the CPU -- like when the drummer
  152. 9:45speeds up when the Roman Galley needs to ram another ship.
  153. 9:48Chip makers often design CPUs with enough tolerance to handle a little bit of overclocking,
  154. 9:52but too much can either overheat the CPU, or produce gobbledygook as the signals fall behind the clock.
  155. 9:58And although you don’t hear very much about underclocking, it’s actually super useful.
  156. 10:02Sometimes it’s not necessary to run the processor at full speed...
  157. 10:04maybe the user has stepped away, or just not running a particularly demanding program.
  158. 10:08By slowing the CPU down, you can save a lot of power, which is important for computers
  159. 10:13that run on batteries, like laptops and smartphones.
  160. 10:15To meet these needs, many modern processors can increase or decrease their clock speed
  161. 10:19based on demand, which is called dynamic frequency scaling.
  162. 10:23So, with the addition of a clock, our CPU is complete.
  163. 10:26We can now put a box around it, and make it its own component.
  164. 10:28Yup.
  165. 10:29A new level of abstraction!
  166. 10:37RAM, as I showed you last episode, lies outside the CPU as its own component, and they communicate
  167. 10:42with each other using address, data and enable wires.
  168. 10:45Although the CPU we designed today is a simplified example, many of the basic mechanics we discussed
  169. 10:50are still found in modern processors.
  170. 10:52Next episode, we’re going to beef up our CPU, extending it with more instructions as
  171. 10:56we take our first baby steps into software.
  172. 10:59I’ll see you next week.

About this transcript

This page contains the full transcript of The Central Processing Unit (CPU): Crash Course Computer Science #7 by CrashCourse, generated from the public captions YouTube serves with the video. The transcript has 2,115 words across 172 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.