All language subtitles for en-2

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified) Download
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,000 --> 00:00:04,840 The CPU, short for Central Processing Unit, is like the brain of the computer, and once 2 00:00:04,840 --> 00:00:07,960 you understand how it works, you'll understand the computer as well. 3 00:00:07,960 --> 00:00:12,320 Let's remove the cover of the CPU and zoom in to see what happens inside. 4 00:00:12,320 --> 00:00:15,820 There are lots of different wires carrying information around the CPU. 5 00:00:15,820 --> 00:00:20,840 This particular CPU is called the 6502 and was used in computers like the Apple II and 6 00:00:20,840 --> 00:00:25,500 the Commodore 64, as well as in the original Nintendo Entertainment System. 7 00:00:25,500 --> 00:00:31,280 This simulation of the 6502 can be found online at visual6502.org. 8 00:00:31,280 --> 00:00:35,680 In every CPU, there is a particular wire that turns on and off at a steady rate to help 9 00:00:35,680 --> 00:00:37,360 keep everything in sync. 10 00:00:37,360 --> 00:00:42,020 That wire is called the clock, and the clock in this simulation is turning on about twice 11 00:00:42,020 --> 00:00:43,060 a second. 12 00:00:43,060 --> 00:00:47,600 Modern CPUs are measured in gigahertz, giga meaning billion and hertz meaning times per 13 00:00:47,600 --> 00:00:52,820 second, so the clock in modern CPUs turns on several billion times per second. 14 00:00:52,820 --> 00:00:57,360 That speed is what allows CPUs to do very complicated things very quickly. 15 00:00:57,360 --> 00:01:01,960 However, what the CPU does during each clock tick is actually very simple and something 16 00:01:01,960 --> 00:01:03,660 we'll look at more in this video. 17 00:01:03,660 --> 00:01:06,400 For now, we'll zoom back out and put the cover back on. 18 00:01:06,400 --> 00:01:12,240 The CPU in your computer might be manufactured by a company like Intel or AMD, but the type 19 00:01:12,240 --> 00:01:15,880 of CPU we're going to look at today is called the Scott CPU. 20 00:01:15,880 --> 00:01:20,560 The Scott CPU doesn't actually exist except as a design in a book called But How Do It 21 00:01:20,560 --> 00:01:22,200 Know by John Scott. 22 00:01:22,200 --> 00:01:26,600 The design of the Scott CPU is copyrighted and is being used in this video with John's 23 00:01:26,600 --> 00:01:27,600 permission. 24 00:01:27,600 --> 00:01:30,500 The book is available at buthowdoitknow.com. 25 00:01:30,500 --> 00:01:34,880 This is a great book that goes through each of the components in the CPU very slowly, 26 00:01:34,880 --> 00:01:37,460 without using a lot of overly technical jargon. 27 00:01:37,460 --> 00:01:41,420 If you've been looking for a book that explains how a computer works, I would highly recommend 28 00:01:41,420 --> 00:01:42,420 this one. 29 00:01:42,420 --> 00:01:44,920 So let's flip the CPU over and look underneath. 30 00:01:44,920 --> 00:01:49,280 You'll see a lot of pins sticking out that allow the CPU to take in information and send 31 00:01:49,280 --> 00:01:50,280 it back out. 32 00:01:50,280 --> 00:01:52,800 The CPU fits into what's known as the motherboard. 33 00:01:52,800 --> 00:01:56,660 The motherboard allows all the components in the computer to connect to each other. 34 00:01:56,660 --> 00:02:00,120 So we'll flip the CPU back over and plug it into the motherboard. 35 00:02:00,120 --> 00:02:03,520 On the right of the motherboard is a place for something called RAM. 36 00:02:03,520 --> 00:02:07,600 RAM is short for Random Access Memory, and it just contains all the data that is being 37 00:02:07,600 --> 00:02:09,440 processed by the CPU. 38 00:02:09,440 --> 00:02:13,920 Let's learn a little bit more about RAM by looking at how the CPU and RAM interact. 39 00:02:13,920 --> 00:02:18,080 For now, we'll remove the wires on the left and move the motherboard over to make room 40 00:02:18,080 --> 00:02:19,480 for the RAM chip. 41 00:02:19,480 --> 00:02:24,160 RAM consists of a list of addresses, and at each of those addresses is a piece of data. 42 00:02:24,160 --> 00:02:29,280 The CPU normally requests and processes each piece of data from RAM in order, one after 43 00:02:29,280 --> 00:02:30,280 the other. 44 00:02:30,280 --> 00:02:34,280 However, if the CPU is instructed to pull data out of order, it can do so. 45 00:02:34,280 --> 00:02:36,600 That is why it's called Random Access Memory. 46 00:02:36,600 --> 00:02:40,960 The data can be accessed randomly if it needs to be, although normally it's accessed in 47 00:02:40,960 --> 00:02:41,960 order. 48 00:02:41,960 --> 00:02:46,360 When the computer first starts running a program, it sends an address to RAM to begin retrieving 49 00:02:46,360 --> 00:02:47,400 that program. 50 00:02:47,400 --> 00:02:52,000 The RAM address just consists of a series of ones and zeros, representing on and off 51 00:02:52,000 --> 00:02:53,000 wires. 52 00:02:53,000 --> 00:02:57,720 RAM doesn't do anything with that address, though, until the CPU also turns on the Set 53 00:02:57,720 --> 00:02:59,320 or the Enable wire. 54 00:02:59,320 --> 00:03:04,980 If the Enable wire is turned on, RAM automatically sends whatever piece of data is at that address 55 00:03:04,980 --> 00:03:06,440 back to the CPU. 56 00:03:06,440 --> 00:03:09,600 That data is then processed by the CPU accordingly. 57 00:03:09,600 --> 00:03:13,480 Once the CPU is finished processing that piece of data, it then sends another address to 58 00:03:13,480 --> 00:03:17,600 RAM, turns on the Enable wire, and gets the next piece of data from RAM. 59 00:03:17,600 --> 00:03:20,840 This process happens over and over again inside the computer. 60 00:03:20,840 --> 00:03:27,000 If the CPU needs to save data to RAM, it outputs an address, outputs some data, and then turns 61 00:03:27,000 --> 00:03:28,440 on the Set wire. 62 00:03:28,440 --> 00:03:32,080 The RAM will then overwrite the data at that address with the new data. 63 00:03:32,080 --> 00:03:34,200 But what is that data inside RAM? 64 00:03:34,200 --> 00:03:36,400 Because it just looks like a bunch of ones and zeros. 65 00:03:36,400 --> 00:03:38,460 Well, it's made up of different things. 66 00:03:38,460 --> 00:03:42,440 Some of the most important pieces of data in RAM are the instructions. 67 00:03:42,440 --> 00:03:45,240 Instructions just tell the CPU to do different things. 68 00:03:45,240 --> 00:03:47,320 There are also numbers inside that data. 69 00:03:47,320 --> 00:03:51,440 These are numbers that you might want to add together, compare, or simply process in some 70 00:03:51,440 --> 00:03:52,440 way. 71 00:03:52,440 --> 00:03:55,560 Another thing, and this is kind of weird, that is in the data is addresses. 72 00:03:55,560 --> 00:04:00,480 At particular memory addresses in RAM, the data itself is also an address. 73 00:04:00,480 --> 00:04:03,000 These addresses can be used for various things. 74 00:04:03,000 --> 00:04:06,960 For instance, if you want to output a number to an external device, you have to know the 75 00:04:06,960 --> 00:04:08,840 address of that particular device. 76 00:04:08,840 --> 00:04:10,800 Do you want to send data to the printer? 77 00:04:10,800 --> 00:04:13,080 Or do you want to send it to the monitor, for instance? 78 00:04:13,080 --> 00:04:15,240 There are also letters stored in RAM. 79 00:04:15,240 --> 00:04:18,640 If you want to show some text on the screen, you would actually store it as a bunch of 80 00:04:18,640 --> 00:04:20,280 ones and zeros in RAM. 81 00:04:20,280 --> 00:04:24,560 Each letter is stored as a particular combination of ones and zeros according to a character 82 00:04:24,560 --> 00:04:25,560 code. 83 00:04:25,560 --> 00:04:27,120 These character codes are arbitrary. 84 00:04:27,120 --> 00:04:32,860 Someone just decided that this is a lowercase a, and this is an uppercase G, for instance. 85 00:04:32,860 --> 00:04:35,640 So that's what's actually in the data inside RAM. 86 00:04:35,640 --> 00:04:38,640 Now let's go back to seeing the data as just a bunch of ones and zeros. 87 00:04:38,640 --> 00:04:42,040 We will now move the RAM chip into the RAM socket on the motherboard. 88 00:04:42,040 --> 00:04:46,800 We will then group the RAM addresses and data together, pull the CPU out of the motherboard, 89 00:04:46,800 --> 00:04:50,520 and look at what's called the instruction set of the CPU. 90 00:04:50,520 --> 00:04:55,840 As we saw earlier, some of the pieces of data in RAM are instructions, and each CPU has 91 00:04:55,840 --> 00:04:59,560 its own set of instructions that it understands. 92 00:04:59,560 --> 00:05:05,000 So there might be a load instruction, which loads a number from RAM into the CPU. 93 00:05:05,000 --> 00:05:08,800 After a couple of these load instructions, there might be an add instruction that adds 94 00:05:08,800 --> 00:05:10,980 these two numbers together. 95 00:05:10,980 --> 00:05:15,200 After an add instruction might be a store instruction, which saves the result of that 96 00:05:15,200 --> 00:05:18,880 addition back out to RAM to be used later on. 97 00:05:18,880 --> 00:05:23,600 There might also be a compare instruction after some load instructions, which compares 98 00:05:23,600 --> 00:05:27,920 two numbers together to see which one is larger or if they are the same. 99 00:05:27,920 --> 00:05:32,000 The compare instruction can be very useful when used in conjunction with what's called 100 00:05:32,000 --> 00:05:34,680 a jump if instruction. 101 00:05:34,680 --> 00:05:40,380 As we saw earlier, the CPU generally requests each piece of data from RAM in order one after 102 00:05:40,380 --> 00:05:41,380 the other. 103 00:05:41,380 --> 00:05:46,280 Sometimes, though, the programmer wants to jump to an out-of-order RAM address to process 104 00:05:46,280 --> 00:05:48,720 some other instructions in memory. 105 00:05:48,720 --> 00:05:54,240 The jump if instruction checks to see if a certain condition is true before it jumps. 106 00:05:54,240 --> 00:05:58,720 It uses the results of the compare instruction to make this decision. 107 00:05:58,720 --> 00:06:02,560 There is also a regular jump instruction that jumps no matter what. 108 00:06:02,560 --> 00:06:07,160 Finally, there is an out instruction and an in instruction. 109 00:06:07,160 --> 00:06:12,840 These will output data to an external device, like a monitor, or input data from an external 110 00:06:12,840 --> 00:06:15,200 device, like a keyboard. 111 00:06:15,200 --> 00:06:20,900 These two instructions are often used in conjunction with an address, like we talked about earlier. 112 00:06:20,900 --> 00:06:24,800 There are some other instructions in the CPU's instruction set, but these are some of the 113 00:06:24,800 --> 00:06:27,280 more commonly seen ones. 114 00:06:27,280 --> 00:06:33,600 So as we saw, the data in RAM consists of things like instructions, numbers, addresses, 115 00:06:33,600 --> 00:06:35,000 and letters. 116 00:06:35,000 --> 00:06:40,100 So let's go through a program that would use this instruction set to play a guessing game. 117 00:06:40,100 --> 00:06:44,320 So it would load a number like 9 into the CPU. 118 00:06:44,320 --> 00:06:47,880 Let's say that the programmer decided that that was the right answer, so he went ahead 119 00:06:47,880 --> 00:06:50,120 and put that number into RAM. 120 00:06:50,120 --> 00:06:54,120 And then comes an in instruction to retrieve the user's guess. 121 00:06:54,120 --> 00:06:58,000 After the in instruction is the address of the keyboard, so we can know where we are 122 00:06:58,000 --> 00:06:59,940 getting the data from. 123 00:06:59,940 --> 00:07:04,680 Next comes a compare instruction that checks to see if those two numbers, the one saved 124 00:07:04,680 --> 00:07:09,280 by the programmer and the one entered by the user, are the same. 125 00:07:09,280 --> 00:07:13,800 Following the compare instruction is a jump if equal instruction, which will jump to another 126 00:07:13,800 --> 00:07:18,800 address in RAM if those two numbers we just talked about are the same. 127 00:07:18,800 --> 00:07:23,640 The jump if equal instruction is immediately followed by a new RAM address. 128 00:07:23,640 --> 00:07:28,520 If the two numbers are the same, the CPU jumps to that new address to begin processing its 129 00:07:28,520 --> 00:07:31,120 next set of instructions from there. 130 00:07:31,120 --> 00:07:35,680 If the two numbers are not the same, then the computer ignores the jump if equal instruction 131 00:07:35,680 --> 00:07:39,600 and the corresponding address and just keeps going. 132 00:07:39,600 --> 00:07:44,560 Following the jump to address comes an out instruction with the address for the monitor, 133 00:07:44,560 --> 00:07:51,060 then the letter capital G, and then below that would be the letters U, E, S, S, space 134 00:07:51,060 --> 00:07:54,040 again, so guess again. 135 00:07:54,040 --> 00:07:58,400 So if the user guesses the wrong number, the program would tell him to guess again, and 136 00:07:58,400 --> 00:08:03,560 then jump back up to the in instruction to retrieve that new guess and then process these 137 00:08:03,560 --> 00:08:06,280 instructions all over again. 138 00:08:06,280 --> 00:08:11,600 By the way, the in and out instructions used here have been simplified somewhat, but you 139 00:08:11,600 --> 00:08:14,760 will find them covered in more detail in the book. 140 00:08:14,760 --> 00:08:19,600 So now, let's briefly take a look inside the CPU itself to see how it would process an 141 00:08:19,600 --> 00:08:21,200 instruction. 142 00:08:21,200 --> 00:08:26,160 As we saw earlier, this is the inside of the 6502 CPU. 143 00:08:26,160 --> 00:08:31,400 Let's take away the 6502 wiring and see what's inside the Scott CPU. 144 00:08:31,400 --> 00:08:36,280 The first component is the control unit, which is kind of like a captain in the army. 145 00:08:36,280 --> 00:08:41,400 It receives its orders from RAM in the form of an instruction, and then breaks that instruction 146 00:08:41,400 --> 00:08:45,280 down into specific commands for the other components. 147 00:08:45,280 --> 00:08:49,380 One of the most important components under the command of the control unit is the arithmetic 148 00:08:49,380 --> 00:08:52,940 logic unit, or ALU for short. 149 00:08:52,940 --> 00:08:58,680 The ALU is what performs all the mathematical operations inside the CPU, such as addition, 150 00:08:58,680 --> 00:09:02,360 subtraction, or even comparison like we saw earlier. 151 00:09:02,360 --> 00:09:05,280 The arithmetic logic unit has two inputs. 152 00:09:05,280 --> 00:09:10,320 We'll label them input A and input B, and assume they are two numbers from some previous 153 00:09:10,320 --> 00:09:12,400 load instructions. 154 00:09:12,400 --> 00:09:15,380 Now we might want to add those two numbers together. 155 00:09:15,380 --> 00:09:19,800 The control unit receives that instruction from RAM and then tells the ALU what type 156 00:09:19,800 --> 00:09:22,080 of operation to perform. 157 00:09:22,080 --> 00:09:26,360 The ALU performs the operation and then outputs the answer. 158 00:09:26,360 --> 00:09:30,920 Sometimes though, depending upon the type of instruction, the output from the ALU can 159 00:09:30,920 --> 00:09:32,880 actually be ignored. 160 00:09:32,880 --> 00:09:38,680 For instance, if you have a compare instruction, the ALU doesn't need to output an answer. 161 00:09:38,680 --> 00:09:43,600 Instead, it just needs to tell the control unit how the two numbers compare to each other. 162 00:09:43,600 --> 00:09:48,800 For this, the ALU uses what are called flags, and they help the control unit decide what 163 00:09:48,800 --> 00:09:54,400 to do when it receives the next instruction, like jump if, which we'll see later. 164 00:09:54,400 --> 00:09:59,360 For now though, let's say that we are working with an instruction that does produce an output. 165 00:09:59,360 --> 00:10:01,240 Where does that output actually go? 166 00:10:01,240 --> 00:10:07,040 Well, the eight wires coming out of the ALU would actually run to what is called a register. 167 00:10:07,040 --> 00:10:12,880 A register is a very simple component whose only job is to store a number temporarily. 168 00:10:12,880 --> 00:10:17,760 Registers act just like RAM, except they are inside the CPU, making them faster and more 169 00:10:17,760 --> 00:10:23,100 useful for storing a number temporarily while an instruction is being processed. 170 00:10:23,100 --> 00:10:28,700 When the ALU sends the output to the register, it won't actually be saved until the control 171 00:10:28,700 --> 00:10:31,700 unit turns on the register's set wire. 172 00:10:31,700 --> 00:10:35,720 The set wire is just like the one we saw earlier for RAM. 173 00:10:35,720 --> 00:10:41,720 When the set wire is turned on, the register saves whatever number is on its input wires. 174 00:10:41,720 --> 00:10:45,720 Once we have the output saved in the register though, how do we get it back out? 175 00:10:45,720 --> 00:10:50,560 Well, when we are ready to move a number out of the register, we need another control wire, 176 00:10:50,560 --> 00:10:55,720 called the enable wire, that also runs from the control unit to the register. 177 00:10:55,720 --> 00:11:00,520 As soon as the control unit turns the enable wire on, the register will output whatever 178 00:11:00,520 --> 00:11:02,800 number is saved inside. 179 00:11:02,800 --> 00:11:07,320 The output wires of the register then connect to what is called the CPU bus. 180 00:11:07,320 --> 00:11:12,960 A bus, as we saw earlier on the motherboard, is simply a group of wires that connect multiple 181 00:11:12,960 --> 00:11:15,600 components inside a computer. 182 00:11:15,600 --> 00:11:20,320 On the bus are some other registers with their own set and enable wires. 183 00:11:20,320 --> 00:11:24,560 These may have numbers from previous instructions already saved inside. 184 00:11:24,560 --> 00:11:28,400 So the control unit will then turn on the set wire of the particular register that it 185 00:11:28,400 --> 00:11:33,000 wants to save that number to, and that number will be saved in that register. 186 00:11:33,000 --> 00:11:37,680 Afterward, the control unit will then turn off the enable wire from the first register 187 00:11:37,680 --> 00:11:39,520 and clear the bus. 188 00:11:39,520 --> 00:11:44,400 The four registers at the top are just used for storing numbers between operations, so 189 00:11:44,400 --> 00:11:48,960 they have output wires that go directly back onto the bus. 190 00:11:48,960 --> 00:11:53,640 So now we have moved a number from one register to another just by turning some wires on and 191 00:11:53,640 --> 00:11:54,640 off. 192 00:11:54,640 --> 00:11:59,200 That's the advantage of the bus, easily moving numbers between components. 193 00:11:59,200 --> 00:12:04,280 The disadvantage of the bus is that you can only have one number on it at a time. 194 00:12:04,280 --> 00:12:08,920 Because of this limitation, the arithmetic logic unit uses a temporary register for input 195 00:12:08,920 --> 00:12:14,520 B. When the control unit is processing an instruction involving the ALU, it will move 196 00:12:14,520 --> 00:12:17,560 one of the inputs to the temporary register. 197 00:12:17,560 --> 00:12:22,800 The temporary register has no need for an enable wire since it only outputs to the ALU 198 00:12:22,800 --> 00:12:26,020 and doesn't conflict with any other registers. 199 00:12:26,020 --> 00:12:29,760 The other input to the ALU comes directly from the bus. 200 00:12:29,760 --> 00:12:34,320 The control unit will enable another register and that number will become input A to the 201 00:12:34,320 --> 00:12:36,080 ALU. 202 00:12:36,080 --> 00:12:41,440 That number stays on the bus until the ALU is finished processing the instruction. 203 00:12:41,440 --> 00:12:46,280 And so now there are two inputs to the ALU and we're ready for the ALU to perform an 204 00:12:46,280 --> 00:12:47,940 operation. 205 00:12:47,940 --> 00:12:53,160 As we saw earlier, the control unit knows what operation to tell the ALU to perform 206 00:12:53,160 --> 00:12:56,640 because of the instruction it receives from RAM. 207 00:12:56,640 --> 00:13:01,680 The instruction itself is in another register called the instruction register. 208 00:13:01,680 --> 00:13:05,920 By the way, the input wires from the bus won't affect this register since the instruction 209 00:13:05,920 --> 00:13:08,720 was already saved in a previous step. 210 00:13:08,720 --> 00:13:13,500 This register, like the temporary register, also has no need for an enable wire since 211 00:13:13,500 --> 00:13:16,680 it just outputs to the control unit. 212 00:13:16,680 --> 00:13:21,320 Based upon this instruction, the control unit then tells the ALU what type of operation 213 00:13:21,320 --> 00:13:23,060 to perform. 214 00:13:23,060 --> 00:13:27,200 So let's say the instruction we're processing is a compare instruction. 215 00:13:27,200 --> 00:13:32,420 With a compare instruction, we're not interested in the number that is output by the ALU. 216 00:13:32,420 --> 00:13:36,240 We only want to know how the two inputs compare to each other. 217 00:13:36,240 --> 00:13:39,960 For that, we use the flags that we talked about earlier. 218 00:13:39,960 --> 00:13:44,560 Each flag is just a wire that turns on or off depending upon whether or not a certain 219 00:13:44,560 --> 00:13:46,760 condition is true. 220 00:13:46,760 --> 00:13:51,760 Inside the Scott CPU, there are four flags and we'll look at two of them now. 221 00:13:51,760 --> 00:13:58,040 The A is larger flag will turn on if input A is larger than input B. If the inputs are 222 00:13:58,040 --> 00:14:03,400 the same, then the equal flag turns on, and if both of these flags are off, that means 223 00:14:03,400 --> 00:14:05,960 input B is larger. 224 00:14:05,960 --> 00:14:11,280 But in this case, the equal flag is on, so that means both inputs are the same. 225 00:14:11,280 --> 00:14:16,460 Once the compare instruction is over, we still need to use the flags for the next instruction, 226 00:14:16,460 --> 00:14:21,200 so we'll save them to a register that only has four inputs and four outputs, one for 227 00:14:21,200 --> 00:14:22,880 each flag. 228 00:14:22,880 --> 00:14:28,360 Once the flags are set into the flags register, the CPU is finished with the compare instruction 229 00:14:28,360 --> 00:14:31,640 and it can then request the next instruction from RAM. 230 00:14:31,640 --> 00:14:37,360 Generally, the next instruction after a compare instruction is a jump if instruction. 231 00:14:37,360 --> 00:14:41,900 This combination of a compare and a jump if instruction, by the way, is very common in 232 00:14:41,900 --> 00:14:43,840 computer programming. 233 00:14:43,840 --> 00:14:48,480 Anytime there is more than one possible path through a program, the computer is using these 234 00:14:48,480 --> 00:14:51,240 instructions to tell it which way to go. 235 00:14:51,240 --> 00:14:54,800 So now that we're finished with the compare instruction and our flags are saved in the 236 00:14:54,800 --> 00:14:59,480 flags register, we need to tell RAM that we're ready for the next piece of data, in this 237 00:14:59,480 --> 00:15:01,860 case the next instruction. 238 00:15:01,860 --> 00:15:06,920 So inside the CPU, another register that is very important is what's called the instruction 239 00:15:06,920 --> 00:15:09,000 address register. 240 00:15:09,000 --> 00:15:14,640 The CPU uses this register to know where the next instruction should come from in RAM. 241 00:15:14,640 --> 00:15:19,440 When the CPU is ready for the next instruction, it enables the instruction address register 242 00:15:19,440 --> 00:15:20,920 onto the bus. 243 00:15:20,920 --> 00:15:26,000 Eventually the instruction address will flow to RAM, but it doesn't get there directly. 244 00:15:26,000 --> 00:15:31,140 There is an intermediary register called the memory address register, whose only job is 245 00:15:31,140 --> 00:15:38,000 to tell RAM what memory address the CPU wants next, since it won't always be an instruction. 246 00:15:38,000 --> 00:15:42,720 Once the instruction address is set into the memory address register, it is automatically 247 00:15:42,720 --> 00:15:47,560 sent to RAM, since the memory address register doesn't have an enable wire. 248 00:15:47,560 --> 00:15:52,660 The control unit then turns on the enable RAM wire, and RAM automatically sends back 249 00:15:52,660 --> 00:15:57,220 the data at that address, which in this case is an instruction. 250 00:15:57,220 --> 00:16:02,320 That instruction is then saved in the instruction register, and the control unit begins processing 251 00:16:02,320 --> 00:16:03,320 it. 252 00:16:03,320 --> 00:16:09,440 In this case, it's a jump if equal instruction, which checks to see if the equal flag is on. 253 00:16:09,440 --> 00:16:15,640 It does that by running one of its wires, and the equal flag wire, into an AND gate. 254 00:16:15,640 --> 00:16:21,200 If both inputs to the AND gate are on, then the output wire turns on as well. 255 00:16:21,200 --> 00:16:24,120 This output wire will then trigger the jump. 256 00:16:24,120 --> 00:16:29,920 That jump eventually retrieves the next piece of data from RAM, which happens to be an address, 257 00:16:29,920 --> 00:16:33,260 and move it into the instruction address register. 258 00:16:33,260 --> 00:16:38,160 When the jump if equal instruction is over, the CPU then processes the instruction at 259 00:16:38,160 --> 00:16:39,880 that new address. 260 00:16:39,880 --> 00:16:44,400 At that new address may be some instructions that output the text, you guessed correctly, 261 00:16:44,400 --> 00:16:48,360 onto the screen, because now we know that the user guessed correctly. 262 00:16:48,360 --> 00:16:53,240 So we'll add the final four wires to our CPU, which are used to control the external devices 263 00:16:53,240 --> 00:16:55,680 like the monitor and the keyboard. 264 00:16:55,680 --> 00:17:00,320 We now have a nearly complete picture of what the Scott CPU looks like. 265 00:17:00,320 --> 00:17:05,360 Data moves around inside the CPU using the bus, and is stored in each register according 266 00:17:05,360 --> 00:17:08,400 to how that data is going to be used. 267 00:17:08,400 --> 00:17:12,840 Each instruction that we have seen can be processed by the Scott CPU in about 6 clock 268 00:17:12,840 --> 00:17:14,360 ticks. 269 00:17:14,360 --> 00:17:19,200 Modern CPUs can process multiple instructions per clock tick, meaning that the computer 270 00:17:19,200 --> 00:17:24,560 you're using to watch this video is likely processing tens or even hundreds of billions 271 00:17:24,560 --> 00:17:27,440 of instructions per second. 272 00:17:27,440 --> 00:17:32,000 That phenomenal speed is accomplished by using more than one of each component, and making 273 00:17:32,000 --> 00:17:35,780 sure that all the components are active as much as possible. 274 00:17:35,780 --> 00:17:41,040 This makes modern CPUs much more complicated than the Scott CPU, but they are still fundamentally 275 00:17:41,040 --> 00:17:44,300 doing the same things as the Scott CPU. 276 00:17:44,300 --> 00:17:48,800 So now let's zoom back out and we can see all the wires that run back out to the pins 277 00:17:48,800 --> 00:17:50,240 on the chip. 278 00:17:50,240 --> 00:17:53,740 On the right are the Set RAM and Enable RAM wires. 279 00:17:53,740 --> 00:17:56,400 On the top are the RAM Address wires. 280 00:17:56,400 --> 00:18:01,600 On the bottom are the Data wires that run to both RAM and the external devices. 281 00:18:01,600 --> 00:18:05,040 And on the left are the Input Output Control wires. 282 00:18:05,040 --> 00:18:09,280 So let's zoom back out to see the rest of the chip, and we'll put the cover back on 283 00:18:09,280 --> 00:18:12,960 the CPU and put it back in the motherboard. 284 00:18:12,960 --> 00:18:16,960 Using the ports on the left, we can now plug in the cables that connect our monitor and 285 00:18:16,960 --> 00:18:18,500 our keyboard. 286 00:18:18,500 --> 00:18:23,160 Each of these ports has an address, and that port address is what the CPU uses with an 287 00:18:23,160 --> 00:18:25,720 IN or an OUT instruction. 288 00:18:25,720 --> 00:18:30,120 That port address, by the way, is sent using the data bus, since the address bus in this 289 00:18:30,120 --> 00:18:32,800 computer is only used for RAM. 290 00:18:32,800 --> 00:18:37,180 So we'll zoom out to see how the motherboard fits inside the computer case. 291 00:18:37,180 --> 00:18:41,840 In the computer case is the last component we'll look at, which is the hard drive. 292 00:18:41,840 --> 00:18:46,760 As soon as the power to the computer is turned off, all the data and RAM is lost, so you 293 00:18:46,760 --> 00:18:49,820 have to have a way to store it more permanently. 294 00:18:49,820 --> 00:18:52,520 For that, we use a hard drive. 295 00:18:52,520 --> 00:18:57,640 Inside the hard drive is a spinning disk covered in tiny magnets with a small metal arm floating 296 00:18:57,640 --> 00:18:58,960 above it. 297 00:18:58,960 --> 00:19:02,880 The arm moves around to the different parts of the disk where different data can be stored 298 00:19:02,880 --> 00:19:04,440 and retrieved. 299 00:19:04,440 --> 00:19:09,560 The disk and the arm generally move very, very quickly, but nowhere near as fast as 300 00:19:09,560 --> 00:19:12,120 the CPU can process data. 301 00:19:12,120 --> 00:19:16,200 For this reason, all the data from the hard drive must first be moved to RAM before it 302 00:19:16,200 --> 00:19:17,200 can be processed. 303 00:19:17,200 --> 00:19:21,820 So, we'll put the hard drive back inside the computer and zoom out. 304 00:19:21,820 --> 00:19:25,840 Here we can see the program we just ran and the message telling the user that he guessed 305 00:19:25,840 --> 00:19:27,160 correctly. 306 00:19:27,160 --> 00:19:31,440 So now you've seen the very basics of how a computer processes information. 307 00:19:31,440 --> 00:19:38,040 You'll find much more about the Scott CPU and the book at the website ButHowDoItKnow.com. 308 00:19:38,040 --> 00:19:42,460 Also there are a few small differences between the book and the video, but those shouldn't 309 00:19:42,460 --> 00:19:44,760 detract from your understanding of either. 310 00:19:44,760 --> 00:19:48,080 You can find a list of these differences in the video description. 311 00:19:48,080 --> 00:19:59,960 Thanks for watching. 31956

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.