************Simpletron 3************

 Sim3 computer

Computer Simulation

Simpletron 3 simulates a computer executing a program written in SML, a fakey assembly language. The user can enter a program, then watch the computer assemble and execute each statement.

Programs can manipulate integer data from -9999 to +9999 with the five operations: addition, subtraction, multiplication, division, and exponentiation.

During execution certain fatal errors are detected: attempt to divide by zero, accumulator overflow, invalid operation codes. These errors will produce an error message.

Careless user errors will cause the program to crash. The user must be careful to select and press the correct buttons. A buzzer will notify the user that data input is required so turn on your sound!

Both program and data reside in memory; it's the responsibility of the programmer to prevent overlap. Simpletron 3 has a RAM of 100 addresses from 00 to 99. The memory can be displayed at any time.

Simpletron 3 is an adaptation of EX 7.43 from Java How to Program by Deitel & Deitel, Prentice Hall, a conputer science text used at Duquesne University, Pittsburgh.


SML: an Assembly Language

Simpletron 3 simulates a computer executing a program in assembly language: the language is SML - Simpletron Machine Language. Each SML instruction contains four digits.The first two digits represent the operation code; the second digit pair is the RAM address.
Simpletron3 has a 100 word memory (00...99). All arithmetic instructions leave their results in the accumulator.

OP CODE
10##
11##
20##
21##
30##
31##
32##
33##
34##
40##
41##
42##
43##
MEANING
Read a word from the keyboard into a specific memory location.
Write a word from a specific memory location to the screen.
Load a word from a specific memory location to the accumulator.
Store a word from the accumulator to specific memory location.
Add a word in a specific memory location to the accumulator.
Subtract a word in a specific memory location from the accumulator.
Multiply a word in a specific memory location t the accumulator.
Divide acc by a word in a specific memory location.
Raise a word in the accumulator to a power from a specific memory location.
Branch to specific location in memory.
Branch to a specific location in memory if accumulator is negative.
Branch to a specific location in memory if accumulator is zero.
Halt


Sim3: CPU Simulator

Sample program: adds two integers

  • 1007   Read A, store in 07
  • 1008   Read B, store in 08
  • 2007   Load A in Acc
  • 3008   Add B
  • 2109   Store sum (A+B) in 09
  • 1109   Write sum
  • 4300   Halt

How to Operate Sim3

  1. Press LOAD to begin simulation
  2. Type instruction, press ENTER
  3. Repeat step 2 to enter program
  4. Press DONE button

  5. Press EXECUTION to run program
  6. Repeat step 5 to continue execution
  7. INPUT data at signal buzzer
Computer

Sample Programs

Program: reads two integers; determines and prints the larger.
  • 00  1009  Read A
  • 01  1010  Read B
  • 02  2009  Load A
  • 03  3110  Subtract B
  • 04  4107  if Acc<0 goto 07
  • 05  1109  else Print A
  • 06  4300
  • 07  1110  Print B
  • 08  4300
  • 09  A
  • 10  B

Program: reads a list of integers, calculates the average and prints out the average. Enter 0 to end list.
  • 00 - 1050   Read C, init to 0 (list length count)
  • 01 - 1051   Read i, init to 1 (increments count)
  • 02 - 1052    Read Sum, init to 0
  • 03 - 1053    Read N (enter 0 to END list)
  • 04 - 2053
  • 05 - 4212
  • 06 - 3052
  • 07 - 2152
  • 08 - 2050
  • 09 - 3051
  • 10 - 2150
  • 11 - 4003
  • 12 - 2052
  • 13 - 3350
  • 14 - 2154
  • 15 - 1154
  • 16 - 4300