Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 8 Simplesim This assignment is the first in a sequence of three. It is not strictly necessary to complete this one in order to

Assignment 8 Simplesim
This assignment is the first in a sequence of three. It is not strictly necessary to complete this
one in order to do the other two, but the understanding you gain in completing this
assignment will make writing the third assignment (a major project) much easier.
We start by peeling open a computer, look at its internal structure, and introduce machine
language (assembler-level) programming. Your assignment is to write a program that
simulates a computer, one that can execute machine language programs.
1. Obtaining Assignment Files on Unix
1. Log in to Unix.
2. Run the setup script for Assignment 8 by typing:
setup 8
2. Description of the Simplesim Computer
In this assignment you will write a program to simulate a fictional computer that we will call
the Simplesim. As its name implies it is a simple machine. All information in the Simplesim is
handled in terms of words. A word is a signed four-digit decimal (base 10) number such as
+3364,-1293,+0007,-0001,0000, etc. The Simplesim is equipped with memory and five
registers.
The Simplesim has a 100-word memory and these words are referenced by their location
numbers 00,01,...,99. Each word in the Simplesims memory (always a single signed
four-digit decimal number) may be interpreted as an instruction to be executed, a data
value, or may be uninitialized.
The first register is the accumulator, which is just large enough to hold a single word.
Words from memory must be placed into the accumulator to perform arithmetic on them
or test their values. All arithmetic and branching is done using the accumulator.
The second register is the instruction counter, which is just large enough to hold a memory
location (a two-digit number, 00,01,...,99). The instruction counter is used to hold the
memory location of the next instruction to be executed.
The third register is the instruction register, which, like the accumulator, is just large enough
to hold a single word. The instruction register is used to hold a copy of the instruction (a
word that was pulled out of memory) that is currently being executed.
The fourth and fifth registers are the operation code and operand, respectively. Each one is
just large enough to hold half of a word (a two-digit decimal number). The operation code
and operand registers are used to split the instruction register in half, with the 2 leftmost
digits and sign of the instruction register going into the operation code and the 2 rightmost
digits going into the operand. For example, if the instruction register had +1009, the
operation code would have +10 and the operand would have 09. Likewise, if the
instruction register had -1201, the operation code would have -12 and the operand would
have 01.
3. The Simplesim Machine Language (SML)
Each instruction written in the Simplesim Machine Language (SML) occupies one word of the
Simplesims memory (and hence instructions are signed four-digit decimal numbers). The two
leftmost digits of each SML instruction are the operation code (opcode), which specifies the
operation to be performed. The two rightmost digits of an SML instruction are the operand,
which is the memory location containing the word to which the operation applies. The
complete set of SML instructions is described in the table that follows.
Operation Code Meaning
Input / Output Operations:
#define READ 11 Read a word into a specific memory location.
#define WRITE 12 Print a word from a specific memory location.
Store / Load Operations:
#define STORE 21 Store the word in the accumulator in a specific memory
location.
#define LOAD 22 Load a word from a specific memory location into the
accumulator.
Arithmetic Operations:
#define ADD 31 Add a word in a specific memory location to the word in the
accumulator (leave result in accumulator).
#define SUBTRACT 32 Subtract a word in a specific memory location from the word
in the accumulator (leave result in accumulator).
#define MULTIPLY 33 Multiply a word in a specific memory location by the word in
the accumulator (leave result in accumulator).
#define DIVIDE 34 Divide a word in a specific memory location into the word in
the accumulator (leave result in accumulator).
Transfer of Control Operations:
#define BRANCH 41 Branch to a specific memory location.
#define BRANCHZERO 42 Branch to a specific memory location if the accumulator is
zero.
#define BRANCHNEG 43 Branch to a specific memory location if the accumulator is
negative.
#define HALT 44 Halt, i.e., the program has completed its task.
We illustrate how the Simplesim executes SML programs (using the instructions from the
table above) with the use of two example SML programs. Consider the following SML program
which reads two numbers and computes and prints their sum.
Memory
Location Word Instruction
00+1107(Read A)
01+1108(Read B)
02+2207(Load A)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

You have

Answered: 1 week ago