CPSC 120: Principles of Computer Science,Spring 2002

Lab 4: The "xComputer" Model Computer


IN THIS LAB, YOU WILL BE WORKING with the xComputer model computer that is described in Chapter 3 of the textbook. More precisely, you will be working with a simulation of this computer that runs as a Java applet. The information that you need to use this applet can be found at:

http://math.hws.edu/TMCM/java/labs/xComputerLab1.html

or just go the the CS120 web page and click on the appropriate link.

However, the exercises that you need to do are those listed on this page. You will not have to save any files in your computer account, so it doesn't matter how you run the xComputer applet.



Exercise 1:   Write an xComputer program to compute the value of expression

                35 + 122 - 54 - 17

When the program is run, the computer should store its answer in memory location number 10. Then the computer should halt. To turn in, write out the complete assembly language program that you used.

Exercise 2:   Use the xComputer applet to translate the following assembly language instructions into binary numbers:

             LOD-C 42
             INC
             STO 10

In your answer, list the binary numbers, and write a short paragraph explaining why a computer uses binary numbers to represent machine language instructions.

Exercise 3:   In the lab worksheet, you are asked to step through the steps in the fetch-and-execute cycle for the instruction LOD-C 17. The worksheet contains an explanation of each step in the execution. For this exercise, you should use the xComputer applet to step through the execution of the instructions ADD 17 and ADD-C 17. Explain the purpose of each step in the fetch-and-execute cycle for the two instructions. What differences do you observe between the steps for ADD 17 and for ADD-C 17? Why do these differences occur? (Note: To do this exercise on the xComputer applet, enter the two instructions into memory locations zero and one, and reset the PC to zero. Set the display style to "Control Wires". Then use the "Step" button to step through the fetch-and-execute cycle as the two instruction are executed. The instructions should show up in the Instruction Register. Write down the control wires that are on during each step. When you write up your answer, state what happens during each step, and why.)

Exercise 4:   Modify the first counting program from the lab worksheet so that it will count just from one to ten, stopping when it reaches ten. (The original program is repeated below. It just keeps counting forever.) To do this, each time through the loop, you need to test whether the number is equal to ten. If it is, jump to a HLT instruction at the end of the program. Testing whether a number is ten requires two steps: First, subtract 10 from the number, and then test whether the answer is zero. Use a JMZ instruction to test whether the answer is zero. (This is like a JMP instruction, except that the jump only occurs if the number in the AC is zero.) Write down the modified program, and write a paragraph explaining how your program works.

                lod-c 1    ; This is the original counting program.
                sto 12
                lod 12
                inc
                sto 12
                jmp 2
                hlt        ; Add a halt instruction at the end.

Exercise 5:   We have spent a long time trying to understand how a machine can be made to execute instructions coded as binary numbers. Write a short essay describing the main components of a computer and how they work together to execute programs.


--David Eck (eck@hws.edu), February 2002