CS 101: Introduction to Computer Science
James Madison University, Fall 2022 Semester

Lab03: CPU and RAM simulator

Background

A "computer" is essentially a complex set of digital circuits that are activated as needed. The machine cycle (fetch, decode, and execute) controls the flow of both code and data through a CPU, main memory, and other devices. Today you will gain experience with machine-level instructions, which are the abstract tools that all software systems are based on. Software applications written in high-level languages (like C++, Java, and Python) must be "compiled" into machine instructions before they can run. Operating systems use special purpose machine instructions to control the hardware directly.

Objectives

Part 1: Calculator Tool

Download Lab03-Worksheet.txt
(right-click and Save Link As...)
  1. During this lab, you may use a calculator to convert decimal numbers to their hexadecimal representation. (Make sure you understand how to do this on paper!) The calculator program on a Mac can be set to "programmer" view. The calculator on Windows can also be set to convert decimal to hexidecimal (binary, etc.). Or you can install the following: Calculator

  2. When you first run Calculator, it will be in Basic mode. Change the mode to Programming. This is an example of how that could appear:

  3. Now enter a number (e.g., 92) and see how its hexadecimal and binary representations (5C and 01011100) are shown automatically:

    Here is an example of how this might look. Experiment with the calculator you are using.

  4. You can also change the input to hexadecimal or binary as shown above. The calculator will do arithmetic in whatever base you have selected:

     

  5. Complete the calculator exercises (question 1) in the lab worksheet.

Part 2: Brookshear Machine

Interactive simulator of the Brookshear machine
  • Only type in the white boxes, this is where you type in your program.
  • Use the Step option to step through each line of your program. You will see the orange arrow advance and you will see RAM and registers change as your program directs.
  • Notice the change of the Program counter as you step through your program. Also notice that the Program Counter and orange arrow should refer to the same instruction.
  • Reset CPU will clear the registers.
  • Reset RAM will clear your work in the white boxes
  • Use export to obtain text of your work, you can copy and pasted into the Worksheet.
  1. Use the simulator to complete the following Chapter Review Problems on pages 120--121 of the textbook. Pay careful attention to the address of each bit pattern and the initial value of the program counter. Write your answers to questions 2--5 in the worksheet.

    • #15
    • #16
    • #18 -- explain also in 1-2 sentences what this program does
  2. Convert the following program into machine language. (Note: this is what a "compiler" does for you.) The numbers 74 and 20 are integers in decimal notation. Don't forget to rewrite them as hexadecimal in your instructions!

        x = 74
        y = 20
        z = x + y
    To receive full credit, you must store all variables in main memory. The address of x is 0x20, y is 0x21, and z is 0x22. (Note: "0x" indicates that a nubmer is in hexadecimal.) Use the simulator to test your program.

Submission Instructions