Answered step by step
Verified Expert Solution
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 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 assemblerlevel programming. Your assignment is to write a program that
simulates a computer, one that can execute machine language programs.
Obtaining Assignment Files on Unix
Log in to Unix.
Run the setup script for Assignment by typing:
setup
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 fourdigit decimal base number such as
etc. The Simplesim is equipped with memory and five
registers.
The Simplesim has a word memory and these words are referenced by their location
numbers Each word in the Simplesims memory always a single signed
fourdigit 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 twodigit number, 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 twodigit decimal number The operation code
and operand registers are used to split the instruction register in half, with the leftmost
digits and sign of the instruction register going into the operation code and the rightmost
digits going into the operand. For example, if the instruction register had the
operation code would have and the operand would have Likewise, if the
instruction register had the operation code would have and the operand would
have
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 fourdigit 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 Read a word into a specific memory location.
#define WRITE Print a word from a specific memory location.
Store Load Operations:
#define STORE Store the word in the accumulator in a specific memory
location.
#define LOAD Load a word from a specific memory location into the
accumulator.
Arithmetic Operations:
#define ADD Add a word in a specific memory location to the word in the
accumulator leave result in accumulator
#define SUBTRACT Subtract a word in a specific memory location from the word
in the accumulator leave result in accumulator
#define MULTIPLY Multiply a word in a specific memory location by the word in
the accumulator leave result in accumulator
#define DIVIDE Divide a word in a specific memory location into the word in
the accumulator leave result in accumulator
Transfer of Control Operations:
#define BRANCH Branch to a specific memory location.
#define BRANCHZERO Branch to a specific memory location if the accumulator is
zero.
#define BRANCHNEG Branch to a specific memory location if the accumulator is
negative.
#define HALT Halt, ie 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
Read A
Read B
Load A
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started