YouTube2Text

Registers and RAM: Crash Course Computer Science #6 — Transcript

by CrashCourse · 2,401 words · 198 segments · language en · Watch on YouTube

Full transcript

  1. 0:03Hi, I’m Carrie Anne and welcome to Crash Course Computer Science.
  2. 0:05So last episode, using just logic gates, we built a simple ALU, which performs arithmetic
  3. 0:11and logic operations, hence the ‘A’ and the ‘L’.
  4. 0:13But of course, there’s not much point in calculating a result only to throw it away
  5. 0:17- it would be useful to store that value somehow, and maybe even run several operations in a row.
  6. 0:22That's where computer memory comes in!
  7. 0:24If you've ever been in the middle of a long RPG campaign on your console, or slogging
  8. 0:28through a difficult level on Minesweeper on your desktop, and your dog came by, tripped
  9. 0:32and pulled the power cord out of the wall, you know the agony of losing all your progress.
  10. 0:36Condolences.
  11. 0:38But the reason for your loss is that your console, your laptop and your computers make
  12. 0:42use of Random Access Memory, or RAM, which stores things like game state - as long as
  13. 0:46the power stays on.
  14. 0:47Another type of memory, called persistent memory, can survive without power, and it’s
  15. 0:51used for different things; We'll talk about the persistence of memory in a later episode.
  16. 0:55Today, we’re going to start small - literally by building a circuit that can store one..
  17. 1:00single.. bit of information.
  18. 1:01After that, we’ll scale up, and build our very own memory module, and we’ll combine
  19. 1:05it with our ALU next time, when we finally build our very own CPU!
  20. 1:10INTRO
  21. 1:19All of the logic circuits we've discussed so far go in one direction - always flowing
  22. 1:23forward - like our 8-bit ripple adder from last episode.
  23. 1:26But we can also create circuits that loop back on themselves.
  24. 1:29Let’s try taking an ordinary OR gate, and feed the output back into one of its inputs
  25. 1:34and see what happens.
  26. 1:35First, let’s set both inputs to 0.
  27. 1:37So 0 OR 0 is 0, and so this circuit always outputs 0.
  28. 1:41If we were to flip input A to 1.
  29. 1:441 OR 0 is 1, so now the output of the OR gate is 1.
  30. 1:48A fraction of a second later, that loops back around into input B, so the OR gate sees that
  31. 1:52both of its inputs are now 1.
  32. 1:541 OR 1 is still 1, so there is no change in output.
  33. 1:58If we flip input A back to 0, the OR gate still outputs 1.
  34. 2:01So now we've got a circuit that records a “1” for us.
  35. 2:04Except, we've got a teensy tiny problem - this change is permanent!
  36. 2:07No matter how hard we try, there’s no way to get this circuit to flip back from a 1
  37. 2:12to a 0.
  38. 2:13Now let’s look at this same circuit, but with an AND gate instead.
  39. 2:16We'll start inputs A and B both at 1.
  40. 2:191 AND 1 outputs 1 forever.
  41. 2:21But, if we then flip input A to 0, because it’s an AND gate, the output will go to 0.
  42. 2:26So this circuit records a 0, the opposite of our other circuit.
  43. 2:29Like before, no matter what input we apply to input A afterwards, the circuit will always output 0.
  44. 2:34Now we’ve got circuits that can record both 0s and 1s.
  45. 2:38The key to making this a useful piece of memory is to combine our two circuits into what is
  46. 2:42called the AND-OR Latch.
  47. 2:44It has two inputs, a "set" input, which sets the output to a 1, and a "reset" input, which
  48. 2:48resets the output to a 0.
  49. 2:50If set and reset are both 0, the circuit just outputs whatever was last put in it.
  50. 2:54In other words, it remembers a single bit of information!
  51. 2:58Memory!
  52. 2:59This is called a “latch” because it “latches onto” a particular value and stays that way.
  53. 3:03The action of putting data into memory is called writing, whereas getting the data out
  54. 3:08is called reading.
  55. 3:09Ok, so we’ve got a way to store a single bit of information!
  56. 3:12Great!
  57. 3:13Unfortunately, having two different wires for input – set and reset – is a bit confusing.
  58. 3:18To make this a little easier to use, we really want a single wire to input data, that we
  59. 3:22can set to either 0 or 1 to store the value.
  60. 3:24Additionally, we are going to need a wire that enables the memory to be either available
  61. 3:28for writing or “locked” down --which is called the write enable line.
  62. 3:32By adding a few extra logic gates, we can build this circuit, which is called a Gated Latch
  63. 3:37since the “gate” can be opened or closed.
  64. 3:39Now this circuit is starting to get a little complicated.
  65. 3:41We don’t want to have to deal with all the individual logic gates... so as before, we’re
  66. 3:44going to bump up a level of abstraction, and put our whole Gated Latch circuit in a box
  67. 3:48-- a box that stores one bit.
  68. 3:50Let’s test out our new component!
  69. 3:52Let’s start everything at 0.
  70. 3:54If we toggle the Data wire from 0 to 1 or 1 to 0, nothing happens - the output stays at 0.
  71. 4:00That’s because the write enable wire is off, which prevents any change to the memory.
  72. 4:04So we need to “open” the “gate” by turning the write enable wire to 1.
  73. 4:07Now we can put a 1 on the data line to save the value 1 to our latch.
  74. 4:11Notice how the output is now 1.
  75. 4:14Success!
  76. 4:14We can turn off the enable line and the output stays as 1.
  77. 4:18Once again, we can toggle the value on the data line all we want, but the output will
  78. 4:21stay the same.
  79. 4:22The value is saved in memory.
  80. 4:24Now let’s turn the enable line on again use our data line to set the latch to 0.
  81. 4:29Done.
  82. 4:30Enable line off, and the output is 0.
  83. 4:32And it works!
  84. 4:33Now, of course, computer memory that only stores one bit of information isn’t very
  85. 4:37useful -- definitely not enough to run Frogger.
  86. 4:39Or anything, really.
  87. 4:41But we’re not limited to using only one latch.
  88. 4:43If we put 8 latches side-by-side, we can store 8 bits of information like an 8-bit number.
  89. 4:48A group of latches operating like this is called a register, which holds a single number,
  90. 4:53and the number of bits in a register is called its width.
  91. 4:56Early computers had 8-bit registers, then 16, 32, and today, many computers have registers
  92. 5:01that are 64-bits wide.
  93. 5:03To write to our register, we first have to enable all of the latches.
  94. 5:06We can do this with a single wire that connects to all of their enable inputs, which we set to 1.
  95. 5:11We then send our data in using the 8 data wires, and then set enable back to 0, and
  96. 5:17the 8 bit value is now saved in memory.
  97. 5:19Putting latches side-by-side works ok for a small-ish number of bits.
  98. 5:23A 64-bit register would need 64 wires running to the data pins, and 64 wires running to
  99. 5:28the outputs.
  100. 5:29Luckily we only need 1 wire to enable all the latches, but that’s still 129 wires.
  101. 5:36For 256 bits, we end up with 513 wires!
  102. 5:40The solution is a matrix!
  103. 5:42In this matrix, we don’t arrange our latches in a row, we put them in a grid.
  104. 5:46For 256 bits, we need a 16 by 16 grid of latches with 16 rows and columns of wires.
  105. 5:52To activate any one latch, we must turn on the corresponding row AND column wire.
  106. 5:56Let’s zoom in and see how this works.
  107. 5:58We only want the latch at the intersection of the two active wires to be enabled,
  108. 6:02but all of the other latches should stay disabled.
  109. 6:05For this, we can use our trusty AND gate!
  110. 6:08The AND gate will output a 1 only if the row and the column wires are both 1.
  111. 6:12So we can use this signal to uniquely select a single latch.
  112. 6:15This row/column setup connects all our latches with a single, shared, write enable wire.
  113. 6:20In order for a latch to become write enabled, the row wire, the column wire, and the write
  114. 6:24enable wire must all be 1.
  115. 6:26That should only ever be true for one single latch at any given time.
  116. 6:29This means we can use a single, shared wire for data.
  117. 6:32Because only one latch will ever be write enabled, only one will ever save the data
  118. 6:37-- the rest of the latches will simply ignore values on the data wire because they are not
  119. 6:40write enabled.
  120. 6:41We can use the same trick with a read enable wire to read the data later, to get the data
  121. 6:46out of one specific latch.
  122. 6:48This means in total, for 256 bits of memory, we only need 35 wires - 1 data wire, 1 write
  123. 6:55enable wire, 1 read enable wire, and 16 rows and columns for the selection.
  124. 6:59That’s significant wire savings!
  125. 7:01But we need a way to uniquely specify each intersection.
  126. 7:05We can think of this like a city, where you might want to meet someone at 12th avenue
  127. 7:08and 8th street -- that's an address that defines an intersection.
  128. 7:11The latch we just saved our one bit into has an address of row 12 and column 8.
  129. 7:15Since there is a maximum of 16 rows, we store the row address in a 4 bit number.
  130. 7:2012 is 1100 in binary.
  131. 7:23We can do the same for the column address: 8 is 1000 in binary.
  132. 7:28So the address for the particular latch we just used can be written as 11001000.
  133. 7:35To convert from an address into something that selects the right row or column, we need
  134. 7:39a special component called a multiplexer -- which is the computer component with a pretty cool
  135. 7:43name at least compared to the ALU.
  136. 7:45Multiplexers come in all different sizes, but because we have 16 rows, we need a 1 to
  137. 7:5016 multiplexer.
  138. 7:51It works like this.
  139. 7:52You feed it a 4 bit number, and it connects the input line to a corresponding output line.
  140. 7:56So if we pass in 0000, it will select the very first column for us.
  141. 8:02If we pass in 0001, the next column is selected, and so on.
  142. 8:06We need one multiplexer to handle our rows and another multiplexer to handle the columns.
  143. 8:10Ok, it’s starting to get complicated again, so let’s make our 256-bit memory its own component.
  144. 8:16Once again a new level of abstraction!
  145. 8:24It takes an 8-bit address for input - the 4 bits for the column and 4 for the row.
  146. 8:29We also need write and read enable wires.
  147. 8:32And finally, we need just one data wire, which can be used to read or write data.
  148. 8:37Unfortunately, even 256-bits of memory isn’t enough to run much of anything, so we need
  149. 8:42to scale up even more!
  150. 8:43We’re going to put them in a row.
  151. 8:45Just like with the registers.
  152. 8:46We’ll make a row of 8 of them, so we can store an 8 bit number - also known as a byte.
  153. 8:51To do this, we feed the exact same address into all 8 of our 256-bit memory components
  154. 8:57at the same time, and each one saves one bit of the number.
  155. 9:01That means the component we just made can store 256 bytes at 256 different addresses.
  156. 9:07Again, to keep things simple, we want to leave behind this inner complexity.
  157. 9:11Instead of thinking of this as a series of individual memory modules and circuits, we’ll
  158. 9:15think of it as a uniform bank of addressable memory.
  159. 9:18We have 256 addresses, and at each address, we can read or write an 8-bit value.
  160. 9:23We’re going to use this memory component next episode when we build our CPU.
  161. 9:28The way that modern computers scale to megabytes and gigabytes of memory is by doing the same
  162. 9:32thing we’ve been doing here -- keep packaging up little bundles of memory into larger, and
  163. 9:36larger, and larger arrangements.
  164. 9:37As the number of memory locations grow, our addresses have to grow as well.
  165. 9:428 bits hold enough numbers to provide addresses for 256 bytes of our memory, but that’s all.
  166. 9:48To address a gigabyte – or a billion bytes of memory – we need 32-bit addresses.
  167. 9:53An important property of this memory is that we can access any memory location, at any
  168. 9:58time, and in a random order.
  169. 9:59For this reason, it’s called Random-Access Memory or RAM.
  170. 10:03When you hear people talking about how much RAM a computer has - that's the computer’s memory.
  171. 10:07RAM is like a human’s short term or working memory, where you keep track of things going
  172. 10:11on right now - like whether or not you had lunch or paid your phone bill.
  173. 10:14Here’s an actual stick of RAM - with 8 memory modules soldered onto the board.
  174. 10:18If we carefully opened up one of these modules and zoomed in, The first thing you would see
  175. 10:22are 32 squares of memory.
  176. 10:23Zoom into one of those squares, and we can see each one is comprised of 4 smaller blocks.
  177. 10:28If we zoom in again, we get down to the matrix of individual bits.
  178. 10:31This is a matrix of 128 by 64 bits.
  179. 10:34That’s 8192 bits in total.
  180. 10:37Each of our 32 squares has 4 matrices, so that’s 32 thousand, 7 hundred and 68 bits.
  181. 10:43And there are 32 squares in total.
  182. 10:45So all in all, that’s roughly 1 million bits of memory in each chip.
  183. 10:49Our RAM stick has 8 of these chips, so in total, this RAM can store 8 millions bits,
  184. 10:54otherwise known as 1 megabyte.
  185. 10:56That’s not a lot of memory these days -- this is a RAM module from the 1980’s.
  186. 11:00Today you can buy RAM that has a gigabyte or more of memory - that’s billions of bytes
  187. 11:05of memory.
  188. 11:06So, today, we built a piece of SRAM - Static Random-Access Memory – which uses latches.
  189. 11:11There are other types of RAM, such as DRAM, Flash memory, and NVRAM.
  190. 11:15These are very similar in function to SRAM, but use different circuits to store the individual
  191. 11:19bits -- for example, using different logic gates, capacitors, charge traps, or memristors.
  192. 11:24But fundamentally, all of these technologies store bits of information in massively nested
  193. 11:28matrices of memory cells.
  194. 11:31Like many things in computing, the fundamental operation is relatively simple.. it’s the
  195. 11:35layers and layers of abstraction that’s mind blowing -- like a russian doll that
  196. 11:40keeps getting smaller and smaller and smaller.
  197. 11:42I’ll see you next week.
  198. 11:44Credits

About this transcript

This page contains the full transcript of Registers and RAM: Crash Course Computer Science #6 by CrashCourse, generated from the public captions YouTube serves with the video. The transcript has 2,401 words across 198 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.