Matrix Multiplication: Given two matrices Aij and Bjk the product Cik can be calculated with the following equation:
Write a program that multiplies the following matrices together and stores the results in a new matrix. Print the resulting matrix values to the console.
Modify Histogram Program: Modify the Histogram program given in example 8.8 so that it can count the occurrence of the digits 0 through 9 and the punctuation marks period ‘.’, comma ‘,’, question mark ‘?’, colon ‘:’, and semi-colon ‘;’.
Computer Simulator: You are a Java developer with a high-tech firm doing contract work for the Department of Defense. You company has won the proposal to develop a proof-of-concept model for an Encrypted Instruction Set Computer System Mark 1. (EISCS Mk1) Your job is to simulate the operation of the EISCS Mk1 with a Java application.
Supporting Information: The only language a computer understands is its machine language instruction set. The EISCS Mk1 is no different. The EISCS machine language instruction set will consist of a four-digit integer with the two most significant digits being the operation code (opcode) and the two least significant digits being the operand. For example, in the following instruction...
...the number 11 represents the opcode and the number 33 represents the operand. The following table lists and describes each EISCS machine instruction.
Sample Program: Using the instruction set given in table 8-3 you can write simple programs that will run on the EISCS Mk1 computer simulator. The following program reads two numbers from the input, multiplies them together, and writes the results to the console.
Opcode | Mnemonic | Description |
---|---|---|
Input/Output Operations | ||
10 | READ | Reads an integer value from the console and stores it in memory location identified by the operand. |
11 | WRITE | Writes the integer value stored in memory location operand to the console. |
Load/Store Operations | ||
20 | LOAD | Loads the integer value stored at memory location operand into the accumulator. |
21 | STORE | Stores the integer value residing in the accumulator into memory location operand. |
Arithmetic Operations | ||
30 | ADD | Adds the integer value located in memory location operand to the value stored in the accumulator and leaves the result in the accumulator. |
31 | SUB | Subtracts the integer value located in memory location operand from the value stored in the accumulator and leaves the result in the accumulator. |
32 | MUL | Multiplies the integer value located in memory location operand by the value stored in the accumulator and leaves the result in the accumulator. |
33 | DIV | Divides the integer value stored in the accumulator by the value located in memory location operand. |
Control and Transfer Operations | ||
40 | BRANCH | Unconditional jump to memory location operand. |
41 | BRANCH_NEG | If accumulator value is less than zero jump to memory location operand. |
42 | BRANCH_ZERO | If accumulator value is zero then jump to memory location operand. |
43 | HALT | Stop program execution. |
Memory Location | Instruction/Contents | Action |
---|---|---|
00 | 1007 | Read integer into memory location 07 |
01 | 1008 | Read integer into memory location 08 |
02 | 2007 | Load contents of memory location 07 into accumulator |
03 | 3208 | Multiply value located in memory location 08 by value stored in accumulator. Leave result in accumulator |
04 | 2109 | Store value currently in accumulator to memory location 09 |
05 | 1109 | Write the value located in memory location 09 to the console |
06 | 4010 | Jump to memory location 10 |
07 | ||
08 | ||
09 | ||
10 | 4300 | Halt program |
Basic Operation: This section discusses several aspects of the EISCS computer simulation operation to assist you in completing the project.
Memory: The machine language instructions that comprise an EISCS program must be loaded into memory before the program can be executed by the simulator. Represent the computer simulator’s memory as an array of integers 100 elements long.
Instruction Decoding: Instructions are fetched one at a time from memory and decoded into opcodes and operands before being executed. The following code sample demonstrates one possible decoding scheme:
instruction = memory[program_counter++]; operation_code = instruction / 100; operand = instruction % 100;
Hints:
Use switch/case structure to implement the instruction execution logic
You may hard code sample programs in your simulator or allow a user to enter a program into memory via the console
Use an array of 100 integers to represent memory