CrashCourse · @crashcourse
Instructions & Programs: Crash Course Computer Science #8
Uploaded June 8, 2017 · Length 10:36
Summary
Learn how computer programs are sequences of instructions that tell a CPU what to do, including load, add, subtract, store, jump, and halt.
- cpu instructions
- computer programming basics
- opcodes and registers
- program flow control
- conditional jumps
- infinite loops
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:03
Hi, I’m Carrie Anne and this is Crash Course Computer Science!
- 0:06
Last episode, we combined an ALU, control unit, some memory, and a clock together to
- 0:10
make a basic, but functional Central Processing Unit – or CPU – the beating, ticking heart
- 0:14
of a computer.
- 0:15
We’ve done all the hard work of building many of these components from the electronic
- 0:19
circuits up, and now it’s time to give our CPU some actual instructions to process!
- 0:23
The thing that makes a CPU powerful is the fact that it is programmable – if you write
- 0:28
a different sequence of instructions, then the CPU will perform a different task.
- 0:31
So the CPU is a piece of hardware which is controlled by easy-to-modify software!
- 0:36
INTRO
- 0:44
Let’s quickly revisit the simple program that we stepped through last episode.
- 0:48
The computer memory looked like this.
- 0:50
Each address contained 8 bits of data.
- 0:52
For our hypothetical CPU, the first four bits specified the operation code, or opcode, and
- 0:57
the second set of four bits specified an address or registers.
- 1:00
In memory address zero we have 0010 1110.
- 1:04
Again, those first four bits are our opcode which corresponds to a “LOAD_A” instruction.
- 1:10
This instruction reads data from a location of memory specified in those last four bits
- 1:14
of the instruction and saves it into Register A. In this case, 1110, or 14 in decimal.
- 1:21
So let’s not think of this of memory address 0 as “0010 1110”, but rather as the instruction
- 1:27
“LOAD_A 14”.
- 1:28
That’s much easier to read and understand!
- 1:30
And for me to say!
- 1:31
And we can do the same thing for the rest of the data in memory.
- 1:35
In this case, our program is just four instructions long, and we’ve put some numbers into memory
- 1:39
too, 3 and 14.
- 1:41
So now let’s step through this program:
- 1:42
First is LOAD_A 14, which takes the value in address 14, which is the number 3, and
- 1:47
stores it into Register A.
- 1:49
Then we have a “LOAD_B 15” instruction, which takes the value in memory location 15,
- 1:54
which is the number 14, and saves it into Register B.
- 1:56
Okay.
- 1:57
Easy enough.
- 1:58
But now we have an “ADD” instruction.


