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
- Explain how data are represented, stored, and manipulated by computer hardware.
- Apply computing tools and techniques to solve problems at multiple levels of abstraction.
Part 1: Calculator Tool
Download Lab03-Worksheet.txt
(right-click and Save Link As...) |
-
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).
-
When you first run Calculator, it will be in Basic mode. Change the mode to Programming as shown:
-
Now enter a number (e.g.,
92
) and see how its hexadecimal and binary representations (5C
and01011100
) are shown automatically: -
You can also change the input to hexadecimal or binary as shown above. The calculator will do arithmetic in whatever base you have selected:
-
Complete the calculator exercises (question 1) in the lab worksheet.
Part 2: Brookshear Machine
Click here to download / run the simulator |
-
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
-
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
-
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 is0x20
, y is0x21
, and z is0x22
. (Note: "0x" indicates that a nubmer is in hexadecimal.) Use the simulator to test your program.
Submission Instructions
Submit your completed worksheet via canvas.jmu.edu by 11:59 PM today.