CrashCourse · @crashcourse

Instructions & Programs: Crash Course Computer Science #8

Uploaded June 8, 2017 · Length 10:36

Instructions & Programs: Crash Course Computer Science #8

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.

  1. 0:03

    Hi, I’m Carrie Anne and this is Crash Course Computer Science!

  2. 0:06

    Last episode, we combined an ALU, control unit, some memory, and a clock together to

  3. 0:10

    make a basic, but functional Central Processing Unit – or CPU – the beating, ticking heart

  4. 0:14

    of a computer.

  5. 0:15

    We’ve done all the hard work of building many of these components from the electronic

  6. 0:19

    circuits up, and now it’s time to give our CPU some actual instructions to process!

  7. 0:23

    The thing that makes a CPU powerful is the fact that it is programmable – if you write

  8. 0:28

    a different sequence of instructions, then the CPU will perform a different task.

  9. 0:31

    So the CPU is a piece of hardware which is controlled by easy-to-modify software!

  10. 0:36

    INTRO

  11. 0:44

    Let’s quickly revisit the simple program that we stepped through last episode.

  12. 0:48

    The computer memory looked like this.

  13. 0:50

    Each address contained 8 bits of data.

  14. 0:52

    For our hypothetical CPU, the first four bits specified the operation code, or opcode, and

  15. 0:57

    the second set of four bits specified an address or registers.

  16. 1:00

    In memory address zero we have 0010 1110.

  17. 1:04

    Again, those first four bits are our opcode which corresponds to a “LOAD_A” instruction.

  18. 1:10

    This instruction reads data from a location of memory specified in those last four bits

  19. 1:14

    of the instruction and saves it into Register A. In this case, 1110, or 14 in decimal.

  20. 1:21

    So let’s not think of this of memory address 0 as “0010 1110”, but rather as the instruction

  21. 1:27

    “LOAD_A 14”.

  22. 1:28

    That’s much easier to read and understand!

  23. 1:30

    And for me to say!

  24. 1:31

    And we can do the same thing for the rest of the data in memory.

  25. 1:35

    In this case, our program is just four instructions long, and we’ve put some numbers into memory

  26. 1:39

    too, 3 and 14.

  27. 1:41

    So now let’s step through this program:

  28. 1:42

    First is LOAD_A 14, which takes the value in address 14, which is the number 3, and

  29. 1:47

    stores it into Register A.

  30. 1:49

    Then we have a “LOAD_B 15” instruction, which takes the value in memory location 15,

  31. 1:54

    which is the number 14, and saves it into Register B.

  32. 1:56

    Okay.

  33. 1:57

    Easy enough.

  34. 1:58

    But now we have an “ADD” instruction.