Back to DFS's C Page


OAC Problem Set VI

Machine Language Simulator

Your task is to create a program which simulates a computer running a machine language program which is to be read from disk. You will have three (3) class periods to complete your work.

Further, you are to write two machine language programs to run in your simulator:

  1. A program which prompts the user for two numeric values and reports (a) which is bigger or (b) that they are equal.
  2. A program which prompts the user for a string and then prints out an uppercase version of the string.

I am providing a program and two machine language programs, add.sim and bigger.sim, which work. This is a solution to a problem in Deitel & Deitel. This simulator uses a 4-digit decimal value in each memory location. Locations which contain program code consist of a two digit operator and a two-digit operand. A data location contains a signed four-digit decimal value.

You are to use this program as the basis for developing a simulator for a machine language described below.

The Op codes you are to handle are the following:

ConstantHex ValueBytesMeaning
READNUM102Read numeric value from keyboard & store in RAM
WRITENUM112Write numeric value from RAM to screen
READSTR122Read string from keyboard & store in RAM
WRITESTR132Write string from RAM to screen
WRITENL141Write newline to screen
LOADA202Load int from RAM into accumulator
STOREA212Store int from A into RAM
LOADAIMM223Load hardset int into accumulator
LOADX232Load int from RAM into X
STOREX242Store int from X into RAM
LOADXIMM253Load hardset int into X
LOADABYTE262Load byte from RAM into accumulator
STOREABYTE272Store byte from A into RAM
LOADAIMMBYTE282Load hardset byte into accumulator
LOADAXBYTE291Load byte from RAM into A using X as address
STOREAXBYTE2A1Store byte from A into RAM using X as address
MOVEATOX2C1Move value in A to X
MOVEXTOA2D1Move value in X to A
ADDX301Add X to A
SUBTRACTX311Subtract X from A
MULTIPLYX321Multiply X with A
DIVIDEX331Divide X into A
ADDMEM342Add value in memory to A
SUBTRACTMEM352Subtract value in memory from A
MULTIPLYMEM362Multiply value in memory with A
DIVIDEMEM372Divide value in memory into A
ADDIMM383Add hardset value to A
SUBTRACTIMM393Subtract hardset value from A
MULTIPLYIMM3A3Multiply hardset value with A
DIVIDEIMM3B3Divide hardset value into A
INCA401Increment A
INCX411Increment X
DECA421Decrement A
DECX431Decrement X
BRANCH502Unconditional branch to RAM location
BRANCHNEG512Branch to RAM location if A is negative
BRANCHZERO522Branch to RAM location if A is zero
BRANCHPOS532Branch to RAM location if A is positive
HALT541Terminate program

N.B. Op codes 29 and 2A have been redefined (to function like pointers) and 2B has been eliminated.

Simple adder program:

13 16 // Prompt for x
10 29 // Read number into x
13 16 // Prompt for y
10 2B // Read number into y
20 29 // Load x into A
34 2B // Add y to A
21 2D // Store sum in mem z
13 2F // Output string
11 2D // Output sum
13 3B // Output .
14    // NL
54    // HALT
54 79 70 65 20 69 6E 20 61 20 6E 75 6D 62 65 72 3A 20 00 // Prompt
00 00 // x
00 00 // y
00 00 // z
54 68 65 20 73 75 6D 20 69 73 20 00 // Result string
2E 00 // Period


© DFStermole: 2000-2001
Created 25 Dec 2000
Modified 9 July 2005