Lab 1: Exploritory Laboratory

Programming a simple machine

Due: 9/9/2-14


The goal of this lab is to figure out the operation of a simple computer, and then to program it. You are to do this lab during lab period. You are encouraged to interact with other students, helping each other as you figure things out. But you must in the end do your own works, and submit you own lab report.


You will need to create a lab report with screen shots, the programs you write, and answers to all the questions.

Step one

Consider the simple mahine here: A simple Computer.

Instructions here: Simple Computer Instructions

In order to use this machine you will need to either run it in a 64 bit web browser (Chrome is NOT 64 bit, Netscape is), or download the source code and run it from the command line. To run from the command line, unzip the source file, and execute the following commands:

javac computer
java computer

Step two

Try the three built in programs:

  1. Count to 5
  2. Calculate 4 Factorial
  3. Sum 5 Numbers
Explain the operation of each program in English.

Step three

Write the following three programs:

  1. A program that asks the user for two numbers, does integer division on them them, and then outputs the remainder.

  2. A program that, given Nas an input, calculate the Nth Fibonacci number. (Don't remember what this is? Look it up!)

  3. (optional extra credit) rray program: What would you do if you needed to represent an array of values? For example, what if memory location 60 had a array size (say 10), and then 61-71 had values that needed to be summed. How could you write a program to sum any array (starting from 61) whose size was in 60.

    Figure out how to do this,
    Then write a program that:
    • ask for an array size (N)
    • ask for N values, putting them in an array of contiguous memory locations.
    • After all values are entered, ask for another number, and find the number in the array that is closest to the number entered without being greater.
Lab Report

Show each program in the following form with comments:

INPUT 50   // Get variable A in location 50
INPUT 51   // Get variable B in location 51
LOAD 51    // Load variable B into the accumulator
SUB 50     // AX = AX - A 
STORE 52   // Put result (B-A) into location 52
OUTPUT 52  // Output result (B-A

Next run each program, making a screen shot of each result

Step four

Answer the following questions

  1. What is the purpose of the accumulator?
  2. Why would a computer use an accumulator?
  3. What do you think of this machine? Is it very powerful? What are it's main limitations.
  4. What do you think of this lab? Did it help you understand the concept of machine level programming?

Topic revision: r4 - 2014-09-05 - JimSkon
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback