Question
Create a basic computer simulation for a computer we will call Basic-Computer. This computer will run programs in a language called Basic-Computer machine language. This
Create a basic computer simulation for a computer we will call Basic-Computer. This computer will run programs in a language called Basic-Computer machine language. This computer has the basic computer structure you are familiar with. However, you will be running programs at a machine language level.
The Basic-Computer is equipped with a 100-word memory and an accumulator a special register in which information is placed before the information is used in calculations. Information is maintained in words which are a single byte. A word is a signed four-digit decimal number, such as +2244, -1256, +0007 or -0002. Note memory will be referenced by location numbers 00, 01, 02 . 99.
A program written in Basic-Computer machine code must be loaded into memory before it can be run. The first instruction of the program is always placed in location 00. The simulator will always start execution at location 00.
Each instruction written in Basic-Computer machine language occupies one word of memory. The sign of instructions is always plus. However, signs for data can be either plus or negative. As in a real computer each memory location can hold either a Basic-Computer instruction, data or be unused. The first two digits of a four-digit number, representing an instruction, combine to form the operation code that specifies the operation to be performed. In Figure 1 below are the operation codes for the Basic-Computer computer.
Operation | Code | Meaning |
WriteValue | 34 | Write series of words (integer values) from memory starting operand memory location with length specified in accumulator. |
WriteAscii | 35 | Write series of characters (7-bit ASCII Characters) from memory starting at operand memory location with length specified in the accumulator. |
Read | 33 | Read a word from the keyboard into a specific location in memory. |
Write | 32 | Write a word from a specific location in memory to the screen (Decimal number). |
Load | 31 | Load a word from a specific location in memory into the accumulator. |
Store | 30 | Store a word from the accumulator into a specific location in Memory. |
Add | 21 | Add a word from a specific location in memory to the word in the accumulator (leaving the result in the accumulator). |
Subtract | 20 | Subtract a word from a specific location in memory to the word in the accumulator (leaving the result in the accumulator). |
Divide | 11 | Divide a word from a specific location in memory into the word in the accumulator (leaving the result in the accumulator). |
AddImm | 06 | Add an immediate two-digit operand to the word in the accumulator (leaving the result in the accumulator). |
SubtractImm | 07 | Decrement an immediate two-digit operand to the word in the accumulator (leaving the result in the accumulator). |
MultiplyImm | 08 | Multiple an immediate two-digit operand to the word in the accumulator (leaving the result in the accumulator). |
DivideImm | 09 | Divide an immediate two-digit operand into the word in the accumulator (leaving the result in the accumulator). |
Multiply | 10 | Multiple a word from a specific location in memory times the word in the accumulator (leaving the result in the accumulator). |
Branch | 43 | Branch to a specific location in memory. |
Branchneg | 42 | Branch to a specific location in memory if the accumulator is negative. |
BranchPos | 41 | Branch to a specific location in memory if the accumulator is positive. |
BranchZero | 40 | Branch to a specific location in memory if the accumulator is zero. |
Increment | 25 | Increment the accumulator by 1. |
Decrement | 26 | Decrement the accumulator by 1. |
IncMem | 27 | Increment a word in memory by 1. |
DecMem | 28 | Decrement a word in memory by 1. |
Halt | 50 | Halt the program. |
Figure 1
The last two digits of a Basic-Computer Machine Language instruction combine to form the operand the address of the memory location containing the word to which the operation applies or an immediate value to use in the operation.
Simulate the memory of the Basic-Computer with a single-subscripted array memory that has 100 elements. Use a variable called accumulator to represent the accumulator register. Use a variable called prog_counter, the program counter, to keep track of the location in memory that contains the instruction being executed. Use a variable called operationcode, the operation code, to indicate the operation currently being executed. Use a variable called operand to indicate the memory location on which the current instruction operates. The operand is the right most two digits of the instruction currently being executed. You are not to perform instructions directly in memory. Transfer the next instruction to be performed from memory into a variable called instructionregister, the instruction register. Decode the instruction by looking at the most significant 2 digits of the contents of the instructionregister and place them into operand. When execution starts for Basic-Computer all special registers start out as zero. Once the program is placed in memory and the execution is to start, you will use the prog_counter to point to the memory location that the next instruction is to be executed from. Note program execution will always start at location 00. So at the start of the program execution, prog_counter will be 00.
The sequence of execution is as follows:
Fetch get the next instruction to perform
Decode determine the operation to perform, obtain the data to work on
Perform the operation and modify the prog_counter
Some of the Basic-Computer instructions are simulated as follows:
Read: | cin >> memory[operand] |
Load: | accumulator = memory[operand] |
Add: | accumulator = accumulator + memory[operand] |
Halt: | The program is halted and the message ---- Basic-Computer execution terminated --- Also all registers by name are printed with their final contents as well as all contents of all 100 memory locations. This is called a computer core dump (aka memory dump). |
Branch: | Execution continues at the location specified in the least significant two digits of the instruction. The instruction counter (prog_counter) is modified to point to the location where the next instruction is to be executed. This is known as transfer of control. |
AddImm: | accumulator = accumulator + operand |
Figure 2 shows a sample computer dump.
Registers:
Accumulator |
| +0000 |
Prog_counter |
| 00 |
Instructionregister |
| +0000 |
Operartioncode |
| 00 |
Operand |
| 00 |
Memory:
0 1 2 3 4 5 6 7 8 9
00 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
10 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
20 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
30 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
40 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
50 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
60 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
70 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
80 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
90 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
Figure 2
The Basic-Computer simulator should check for various types of errors. During program load each number the user types in memory must be between -9999 and +9999. Keep prompting the user to reenter the number until the user enters a correct number. Also check during execution of the program for the fatal errors:
Attempts to divide by zero
Attempts to execute invalid operation codes
Accumulator overflow or underflow
When a fatal error is detected, your Basic-Computer simulator should terminate operation and print an error message that indicates the fatal error.
--- Basic-Computer execution abnormally terminated with the fatal error ---
--- Attempt to divide by zero ---
And along with the fatal error message you should dump memory as a snap shot of the machine content at time of the error.
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