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

Lab03: CPU and RAM simulator

Background

Last week we looked at how digital circuits can be designed to perform simple computations. 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 Linux is available from the Menu (just start typing cal).

  2. When you first run Calculator, it will be in Basic mode. Change the mode to Programming as shown:

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

  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

Click here to download / run the simulator
  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
    • #20 -- note: the simulator will not fully run this example code
  2. Enter the following machine language into the simulator, starting at address 00. Step through the code to figure out what it does. Then answer question 6 in your worksheet.

        209e
        2112
        5201
        3208
        c000

  3. 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