Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

What happens when we run code?

Starting the CPU Emulator

We used the CPU Emulator from nand2tetris

For more on how the emulator works see the CPU Emulator Tutorial.

For much more detail about how this all works chapter 4 of the related text book has description of the machine code and assembly language.

Loading a program

We’re not going to do project 5, which is to build a CPU, but instead to use the test programs designed to check if your personally build CPU works with the CPU Emulator they provide to understand a simple canonical CPU.

We’re going to use the test cases from the book’s project 5:

  1. Click the folder above the ROM section

  2. Navigate to projects/05

  3. load add.hack

How does the computer actually add constants?

We’ll use add.hack first.

This program adds constants, 2+3.

It is a program, assembly code that we are loading to the simulator’s ROM, which is memory that gets read only by the CPU.

Run the simulator and watch what each line of the program does.

Notice the following:

The simulator has a few key parts:

If you prefer to read, see section 5.2.1- 5.2.6 of nan2tetris book

The max between two numbers

To compute the maximum value max.hack:

Prepare for Next Class

  1. Refresh your knowledge of logical operations/ logic gates: and, or, xor, not. For an example reference see the logicemu emulator we will use in class

Badges

Review
Practice
  1. Review the notes from today

  2. Run and examine how rect.hack and max.hack in the projects/05/ folder of the CPU Emulator work. Make notes and answer the questions below in assemblyexplore.md.

    1. Write an excerpt of code in a high level compiled language that would compile into this `max.hack``.
    1. What does rect.hack do?
    1. What did you learn trying to figure out how it works?

Experience Report Evidence

no separate evidence

Questions After Today’s Class