A Java 1.1 Applet for a Simple Computer Simulator

The computer has 100 memory locations in a 10 by 10 grid with addresses 0 to 99 numbered from the top left row by row. The computer has a program counter which is stored in register PC and an accumulator AX. You can enter the instruction codes as numbers or as mnemonics using the following table.

Mnemonic Code (1st word) Code (2nd word) Description
STORE 160 n Store the contents of AX in memory location n
LOAD 161 n Load AX with the contents of location n
ADDI 44 n Add n to AX (add immediate)
SUBI 45 n Subtract n from AX (subtract immediate)
ADD 50 n Add the contents of location n to AX
SUB 51 n Subtract the contents of location n from AX
MUL 52 n Multiply the contents AX by the contents of location n
DIV 53 n Divide the contents of AX by the contents of location n
JPOS 127 n Jump to the instruction in location n if AX > 0
JZERO 128 n Jump to the instruction in location n if AX = 0
HALT 0   Halt the execution

Program to count down from 100 to zero

Type the following data into the first row of cells, locations 0 to 6. Use the tab key to move from one cell to the next.
LOAD  99  SUBI  1  JPOS  2  HALT
Now type 100 in the memory cell whose address is 99 (bottom right) and push the run button. Watch register AX count down to 0. To run the program again reset the PC to zero and push the run button. You can step through the program one instruction at a time using the step button.