simulator Basic steps: (top)
- A computer definition needs to be in place. The default is
Mano's basic computer.
- Load a machine language program into memory.
- Press Reset to start the simulator. This operation will put
the PCStart value into the PC.
- Run the program, using one of the following commands
- Next T - simulates a FSM (finite state machine) move. This
is often, but not always, equivalent to a clock tick.
- Next I - simulates a complete machine language instruction.
- Run - keep executing instructions until a HALT instruction
CAUTION: It is very easy to get into an infinite loop!
- Kill - if the program takes too long or has errors
- 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:
- Put the source code you wish to assemble into the "Source
Code" text area.
- Use ORG and END assembler directives
- SETPCSTART (optional), the default is the first ORG
- Press the Assemble button.
- Press the Load Program From Assembler button
- This accomplishes step 2 above, so you are now ready to move
to step 3.
There are a number of features of the assembler independent of the
particular architecture being simulated:
- Labels are always in column 1
- Fields are separated by white space
- The next field is the opcode or one of the assembler
- The following assembler instructions are built-in:
- ORG - specifies the start address of the following code, in
- SETPCSTART - the hex address used to initialize a run,
optional, default is first ORG directive
- DEC - puts a decimal value into a memory location
- HEX - puts a hex value into a memory location, can be either
a hex constant or a label
- CHR - puts a character into a memory location, lowest byte,
use single quotes
- STR - puts a string into a series of memory locations, each
character uses a single byte, the result is packed with 0's
padded at the end of the final word as needed.
- END - the end of this assembly language program
- Comments are indicated using a / (slash) or a ; (semi-colon)
- Best to copy/paste a program from a text file
Menus and Commands (top)
Description of all the commands the simulator accepts. Note that not
all commands are currently implmented.
- File menu
- Assembler - toggle displaying the assembler panel
- New - to be implemented
- Open - load a new computer definition, clearing the current
- Save - to be implemented
- Save As ... - to be implemented
- Print - to be implemented
- Run - after a machine language program has been loaded into
memory and Reset, this will run the program until a halt
command is executed
- Kill Run - tries to stop a runaway program, still being
- Next Tick - executes the current FSM event
- Next Instruction - executes the current instruction
- Reset - sets the PC to value set by SETPCSTART and activates
the Run, Kill Run, Next Tick and Next Instruction buttons
- Set Value - used to set the value of a register or a memory
- Clear Registers - sets the values in all the registers to 0
- Clear Memory - sets the values of all the memory locations
- Load File - used to add to the current computer definition.
Best use is to set registers and memory locations
- Load Asm - reads additional specifications for the assembler
from a file
- Dump - various information about the current computer
- About - general and copyright information
- Simulator Help - this help file
- Computer Help - a section of the computer definition file
explaining some details about the particular computer being
- Assembler Help - a section of the computer definition file
explaining the features of the assembly language for the
particular computer being simulated
- Main buttons
- Load Program From Assembler - the machine code generated by
the assembler, as shown in the Machine Code text area, is
transfered to the memory, and SETPCSTART gives the value of
the PC when Reset is pressed.
- Reset - sets the PC to its initial value, and releases the
simulator to start executing a program
- Next T - executes the current FSM event (as the Next Tick
- Next I - executes the next instruction (as the Next
Instruction menu selection)
- Run - runs the program to a halt instruction (as the Run
- Kill - as the Kill menu selection
- Set Value - as the Set Value menu selection
- Clear Registers - as the Clear Registers menu selection
- Clear Memory - as the Clear Memory menu selection
- Load Program From File - as the Load Program From File menu
- Dump - as the Dump menu selection
- Assembler panel
- Assemble - tries to assemble the text in the Source Code
text area, results are displayed in the Machine Code text
area, and the symbol table is shown in the Assembler Messages
- Dump - various information about the assembler is shown in
the Assembler Messages area
- Central Panel
- Input - type the input stream for a run of the program,
- Hex - the data in this display is interpretted as hex
numbers. Use only 2 hex digits, and spaces between bytes.
- ASCII - the data is interpretted as characters
- Output - displays the output of the program
- Hex - output is displayed as hex encoded bytes
- ASCII - output is displayed as characters
- SimulatorOutput, SimulatorInput and SimulatorHasInput are
built-in for all computer architectures
- Other registers and flags are defined by the computer
definition file, and their contents are shown in both hex
- Radio buttons 1, 2, 4, 8, 16 selects the number of words to
show in each row. The memory locations on the left are
- The main text area displays the current contents of the
entire memory defined for this computer in a scrolling text
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.
- Computer defined by a text file
- Will simulate the operations of a computer defined as a finite
- Specifications look like a register transfer language
- It will show the registers and memory, and update them as the
simulator executes a machine language program stored in the
- It can handle input and output as either ASCII or hex
- It can assemble source code to machine code, and load the
machine code into memory
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:
- Register definitions, using the ram, register and flag
- 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
A detailed description of the syntax of this section is given
- The specifications of the assembly language for this computer.
The keywords surrounding this section are Assembler and
Details of the syntax of this section are also given below.
- setRegister, setFlag and PCStart give specific values to
registers, flags, and indicate what value the PC should be given
when the user presses "Reset".
- InstructionCycleStart specifies the index of the state where
the simulator will stop when the user hits the "Next I" button.
- helpComputer and endHelp surround a text or html specification
of a help file displayed when the user selects Computer Help
from the Help menu.
- 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.
- Comments - lines starting with a // are ignored.
- Blank lines are ignored.
in first column
|name <name>, size <size (dec)>,
inputCount <size (dec)>
|bus, name BUS, size 16, inputCount 7
||name <name>, size <number of words (dec)>
<bits per word (dec)>
|ram,name M, size 4096 16
||name <name>, size <number of bits per word
[, control [LD INR CLR] [, destination <name>
|register, name PC, size 16
register, name AR, size 12, control LD INR
CLR, destination BUS 1
register, name OUTR, size 8, control LD
||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
||name, value (hex)
setRegister, PC, 100
||name, value (hex)
setFlag, I, 1
||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
This computer is defined in
This computer is defined in
| The keyword lines have no options.
| The keyword lines have no options.
|| The state code for the start of an instruction cycle
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
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
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
f 13010, f 13020,
t 4,c CODE == 0, DR < M AR, SC ++
|| next state from this state, default is next
state in file
f 14000, t 5, AC < AC ALU_And DR, SC 0, n 100
which must be met to enter this state.
If there is more than one condition, they are anded
See below for more details.
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 use the following format:
- c R [sb [eb]] [==|!=] v
- R = register name
- sb = start bit index, optional
- eb = end bit index, optional
- v = integer value to assign
- The only operators that are recognized are == for
equals and != for not equals
- Operations assign a new value to a register or memory
- The < symbol is used to indicate that the value of the RHS
is assigned to the location specified by the LHS.
- Spaces are used to separate tokens in these expressions.
- The RHS (right hand side) of an assignment expression may
reference 0, 1, 2, or even more registers or memory locations.
- Example of 0, incrementing SC: SC ++
- Example of 0, assigning a value (0) to IEN, R and SC:
22000, f 21000, t 2, PC ++, IEN 0, R 0, SC 0, n 100
- Example of 1: PC < AR
- Example of 2: AC < AC ALU_And DR
- Example of 3: AC < AC ALU_Add DR E
- Register references may include start bit and end bit
references, as described in Conditions above.
- Example: , I < IR 15, CODE < IR 12 14, AR
< IR 0 11
- Example: AC 0 7 < INPR
- Ram references must be followed by a register whose value is
used to compute the location in memory.
- Example: M
AR < DR
- Example: DR < M AR
Functions: The simulator has the following predefined functions:
|increment the register by 1
|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
|AC < AC ALU_And DR
|ADD the values of the 3 parameters
|AC < AC ALU_Add DR E
|Moves bits from one register to another
|AR < M AR
I < IR 15, CODE < IR 12 14, AR < IR 0 11
|Computes the 1's complement of the first
|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:
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
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:
- word, recognized field names: bytes or bits, default is 8
bits, 1 byte.
- word, bytes 2
- word, bits 40
- format - the f1 and f2 after name are arbitrary, while the f1
after the codeBits field is a keyword in this location.
- format [, name <nameA>] [, words <countW>]
[, fieldCount <countF>] [, codeBits <int0>
<int1>] [, f1 <int2> <int3>] [, f2
<int4> <int5>] [, f3 <int6> <int7>]
- nameA is arbitrary, but should be unique among the format
- countW measured in words for this instruction format
- countF is the number of fields after the mnemonic for this
instruction format, currently supported values are 0, 1, 2,
- codeBits are the bits used in this format to specify the
instruction code. The rest of the bits in this instruction
format are some kind of address bits.
- int<n> are bit counts, 0 is the left most bit of the
instruction. The first should be less than the second (eg,
int0 < int1)
- format, name f1, words 1, fieldCount 0, codeBits 0 15
- format, name f2, words 1, fieldCount 1, codeBits 12 15,
f1 0 11
- mnemonic specification examples
- <mnemonic>, <format name>, <opcode>
- AND, f2, 0000
- AND, f3, 8000
- INC, f1, 7020