Computer Simulator general help

By Nicholas Duchon, copyright 2009-2017, v1

This is the basic help file for the computer simulator.

This program is designed to simulate small computers appropriate for student projects.


Using the simulator Basic steps: (top

  1. A computer definition needs to be in place. The default is Mano's basic computer.
  2. Load a machine language program into memory.
  3. Press Reset to start the simulator. This operation will put the PCStart value into the PC.
  4. Run the program, using one of the following commands
    1. Next T - simulates a FSM (finite state machine) move. This is often, but not always, equivalent to a clock tick.
    2. Next I - simulates a complete machine language instruction.
    3. Run - keep executing instructions until a HALT instruction is reached.
      CAUTION: It is very easy to get into an infinite loop!
    4. Kill - if the program takes too long or has errors
  5. Assembly Language Program - you may type an assembly language program into the "Source Code" text area, or copy and paste from a text file. In this case:
    1. Put the source code you wish to assemble into the "Source Code" text area.
      1. Use ORG and END assembler directives
      2. SETPCSTART (optional), the default is the first ORG directive.
    2. Press the Assemble button.
    3. Press the Load Program From Assembler button
    4. This accomplishes step 2 above, so you are now ready to move to step 3.

Assembler (top)

There are a number of features of the assembler independent of the particular architecture being simulated:

Menus and Commands (top)

Description of all the commands the simulator accepts. Note that not all commands are currently implmented.

Features: (top)

By default, the simulator is set up to load the definitions of Mano's basic computer, which he describes in Chapter 5 of Computer Systems Architecture, 3rd edition. Other computer definitions are possible, and may be loaded from appropriate text files.

Defining the computer: (top)

The definition of a computer is read from a text file with a specific syntax, using the File --> Open command.

The main sections of the computer specification file are:
  1. Register definitions, using the ram, register and flag keywords
  2. The specifications of the finite state machine description of the computer in a register transfer language style syntax.
    The keywords surrounding this section are RTLinstructions and endInstructions.
    A detailed description of the syntax of this section is given below.
  3. The specifications of the assembly language for this computer.
    The keywords surrounding this section are Assembler and endAssembler.
    Details of the syntax of this section are also given below.
  4. setRegister, setFlag and PCStart give specific values to registers, flags, and indicate what value the PC should be given when the user presses "Reset".
  5. InstructionCycleStart specifies the index of the state where the simulator will stop when the user hits the "Next I" button.
  6. helpComputer and endHelp surround a text or html specification of a help file displayed when the user selects Computer Help from the Help menu.
  7. helpAssembler and endHelp similarly surround a text or html specification of a help file displayed when the user selects Assembler Help from the Help menu.
  8. Comments - lines starting with a // are ignored.
  9. Blank lines are ignored.

in first column
options Example
name <name>, size <size (dec)>, inputCount <size (dec)>
bus, name BUS, size 16, inputCount 7
ram name <name>, size <number of words (dec)> <bits per word (dec)>
ram,name M, size 4096 16
register name <name>, size <number of bits per word (dec)>
[, control [LD INR CLR] [, destination <name> <index>]
register, name PC, size 16

register, name   AR, size 12, control LD INR CLR, destination BUS 1

register, name OUTR, size  8, control LD
flag name <name> [, size <size (dec)>]
flag, name I

flag, name IEN, size 5
The keyword lines have no options.
Format of lines in between keywords:
  • numbers in hex
  • first number is address
  • rest are values
  • word by word

10: 1234 ABCD

30: FF01 00AA

100: 2107 7200

setRegister name, value (hex)
setRegister, PC, 100

setFlag name, value (hex)
setFlag, I, 1
PCStart name, value (hex)
PCStart, PC, 100
The keyword lines have not options.
If first characters are "<html>", then the lines in between the two flags are handled as html, otherwise as plain text.
This computer is defined in
Computer System
As helpComputer
This computer is defined in
Computer System
The keyword lines have no options.
The keyword lines have no options.

InstructionCycleStart The state code for the start of an instruction cycle
InstructionCycleStart, 200

RTL Instruction Specification: (top)

This simulator thinks of a computer as a finite state machine, with events as clock ticks, and using conditions on various registers to determine what functions are to be performed and which state is the next state.

Thus, every state of the computer must have a unique index, which is pretty much up to the programmer defining this configuration file.

The basic format for all RTL instructions is an index followed by some comma separated specifications. 

Here are the common flags, with explanations and examples:

initial FSM state
00000, s, t 0, SC 0, IEN 0, R 0, S 1
halt FSM state  00001, h, t 0, S 0 
link this state from another state, more than on
This helps construct the FSM graph
These should be to states previously encountered in the file
00100, f 00000
00200, f 00150, f 00151, f 00155
14000, f 13010, f 13020, t 4,c CODE == 0, DR < M AR, SC ++

clock tick of this state
14000, f 13010, f 13020, t 4,c CODE == 0, DR < M AR, SC ++
next state from this state, default is next state in file
15000, f 14000, t 5,  AC < AC ALU_And DR, SC 0, n 100
condition(s) which must be met to enter this state.
If there is more than one condition, they are anded together.
See below for more details.
00151, f 00120, c SimulatorHasInput == 1, c FGI != 0, n 00200
this is a comment until the next comma
// interrupt processing - t0 - t2
an operation on some register(s) - see next table for details  See next table

Conditions: (top)

Conditions use the following format:

Operations: (top)


Functions: The simulator has the following predefined functions:

Function Comments
increment the register by 1
SC ++
Set a register to a value
R < 0
Increment the value in a register
R < R + 1
AND the values in the left and right parameters of the expression
ADD the values of the 3 parameters
Moves bits from one register to another
I < IR 15, CODE < IR 12 14, AR < IR 0 11
Computes the 1's complement of the first (only) parameter
AC < AC ALU_Complement
Circular left shift of 2 registers
AC < AC ALU_ShiftLeftWithCarry E
Circular right shift of 2 registers
AC < AC ALU_ShiftRightWithCarry E

The code is set up to make it relatively easy to add more functions by creating new classes based on the samples provided. This requires the source code and a Java programming environment. For addition information, see the comments in the source code.

Assembler Instruction Specification: (top)

The primary purpose of the assembler definition part of the computer specification file is the correlation between the assembly language mnemonics and the machine codes. Additional parts of this section of the file include defining specifying the assembly language formats, and the word size used in the computer (in bytes).

At the moment, the assembler will only support 0 and 1 address instructions, and will treat 2 address instructions as a special case, indicating indirect addressing. All 1 address instructions use direct addressing.

If there is more than one machine code associated with a mnemonic, the program currently determines which one to choose based on the field count defined by the format specification in this section of the file and by the number of fields encountered in the assembly language program being processed.

The keywords the program recognizes at this time are "word" and "format". All other lines assume that a mnemonic is being specified. For example: