ITP 136
C# Programming

Alternative 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:

 

Tasks:

 

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:

Input/Output Operation

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.

Load/Store Operations

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.

Arithmetic Operations

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.

Control Transfer Operations

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/contents

Action

00

1010

Read word from input into memory location 10.

01

1011

Read word from input into memory location 11.

02

2010

Load word at memory location 10 into accumulator.

03

3311

Multiply contents of accumulator by contents of memory location 11 and leave results in accumulator.

04

2112

Store the contents of the accumulator into memory location 12.

05

1112

Write the contents of memory location 12 to the console.

06

4015

Branch to memory location 15.

07

0000

08

0000

09

0000

10

0000

11

0000

12

0000

13

0000

14

0000

15

4300

Halt 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


* Adapted from the Simpletron exercises 5.18 & 5.19 of Deitel & Deitel's C++ How To Program Second Edition.