ITP 136
C# Programming I
Project 2
Project Name: The Mark I Mod 0 Encrypted Instruction Set Computer Simulator*
Scenario:
You are a C# developer with a high-tech firm doing contract work for the Department
of Defense. Your company has won the proposal to develop a proof-of-concept
model for an Encrypted Instruction Set Computer. (EISCS MKI). Your job is to
simulate the operation of the EISCS MKI in a C# console application.
Objectives:
Upon completing this project you will have demonstrated your
complete understanding of the following concepts:
- Processing cycle of a computer to include:
- Instruction Fetch
- Instruction Decode
- Instruction Execute
- Results Store
- Architectural components found in typical processors to
include:- accumulator
- instruction counter
- memory
- The use and implementation of the following:
- Arrays
- C# console input and output
- Program execution control structures
Tasks:
- Basic: Implement the Encrypted Instruction Set Computer Simulator
as a C# console application. - Advanced: Implement a simple encryption/decryption algorithm that
can be used to encrypt and decrypt the instructions and data in memory. Decrypt
each instruction and operand when they are fetched from memory. [ This is
optional and you will not lose points if you chose not to do this. ]
Background:
EISCS MKI Language Set
The only language a computer really understands is it’s machine
language instruction set; the EISCS is no different. An EISCS machine
language instruction will consist of a four digit integer with the
two most significant digits being the opcode and the two least
significant digits being the operand. For example…
…would instruct the computer to write the contents of memory
location 33 to the screen. The full set of EISCS opcodes grouped by
function is as follows:
const int READ = 10 | Read an integer from the console into a specific memory location. |
const int WRITE = 11 | Write an integer from a specified memory location to the console. |
const int LOAD = 20 | Load a word from a specified memory location into the accumulator. |
const int STORE = 21 | Store a word from the accumulator into a specified memory location. |
const int ADD = 30 | Add a word from a specified memory location to the contents of the accumulator and leave the results in the accumulator. |
const int SUBTRACT = 31 | Subtract a word from a specified memory location from the contents of the accumulator and leave the results in the accumulator. |
const int DIVIDE = 32 | Divide a word from a specific memory location into the contents of the accumulator and leave the results in the accumulator. |
const int MULTIPLY = 33 | Multiply a word from a specified memory location by the contents of the accumulator and leave the contents in the accumulator. |
const int BRANCH = 40 | Branch to a specified memory location. |
const int BRANCHNEG = 41 | Branch to a specified memory location if the contents of the accumulator is negative. |
const int BRANCHZERO = 42 | Branch to a specified memory location if the contents of the accumulator is zero. |
const int HALT = 43 | Stop program execution – The program has completed its task. |
Sample Program:
Using the EISCS machine language instruction set above you can now
write simple programs for the EISCS.
Memory Location |
Instruction/contentsAction
001010Read word from input into memory location 10.011011Read word from input into memory location 11.022010Load word at memory location 10 into accumulator.033311Multiply contents of accumulator by contents of memory
location 11 and leave results in accumulator.042112Store the contents of the accumulator into memory
location 12.051112Write the contents of memory location 12 to the
console.064015Branch to memory location 15.070000080000090000100000110000120000130000140000154300Halt program
The Basic Operation Of The EISCS
Memory
The machine language instructions that comprise an EISCS program
must be loaded into the EISCS’s memory. The EISCS’s memory is
represented by a 100 element long integer array. It could be declared
as follows:
private int memory[ ] = new int[100];
Instruction Decoding
In order to execute programs correctly the EISCS must be able to separate opcodes
from operands. Take as an example the instruction located at memory location
00 in the sample program above. The word 1010 must be separated into its opcode
(READ) and operand (memory location destination). Since EISCS programs must
be loaded into memory before execution the following C# statements might be
used to extract an instruction from memory prior to execution:
instruction = memory[program_counter];
operation_code = instruction / 100;
operand = instruction % 100;
Hints
- Use a switch/case statement to execute the various instructions once decoded.
* Adapted from the Simpletron exercises 5.18 & 5.19 of Deitel
& Deitel’s C++ How To Program Second Edition.