0% found this document useful (0 votes)
13 views

Help Simulator

This document provides help on using a computer simulator program. It describes loading and running machine language programs, assembling assembly language programs, and the simulator's menus and commands. It also explains how the simulator works, how computers are defined for the simulator, and includes sections on the assembler and features of the program.

Uploaded by

Ritoban Saha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Help Simulator

This document provides help on using a computer simulator program. It describes loading and running machine language programs, assembling assembly language programs, and the simulator's menus and commands. It also explains how the simulator works, how computers are defined for the simulator, and includes sections on the assembler and features of the program.

Uploaded by

Ritoban Saha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

4/12/22, 2:26 AM HelpSimulator

Contents:
Computer Simulator general help
Using the Simulator
By Nicholas Duchon, copyright 2009-2017, v1 The Assembler
Menus and
This is the basic help file for the computer simulator. Commands
Features
This program is designed to simulate small computers appropriate for student Defining the
projects. Computer
RTL Instructions
Assembler
Instructions

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
a. Next T - simulates a FSM (finite state machine) move. This is often, but not always, equivalent
to a clock tick.
b. Next I - simulates a complete machine language instruction.
c. Run - keep executing instructions until a HALT instruction is reached.
CAUTION: It is very easy to get into an infinite loop!
d. 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:
a. 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.
b. Press the Assemble button.
c. Press the Load Program From Assembler button
d. 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:

Labels are always in column 1


Fields are separated by white space
The next field is the opcode or one of the assembler instructions
The following assembler instructions are built-in:
ORG - specifies the start address of the following code, in hex
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

sandsduchon.org/duchon/cs311/CompSim/helpSimulator.html 1/7
4/12/22, 2:26 AM HelpSimulator

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 one
Save - to be implemented
Save As ... - to be implemented
Print - to be implemented
Quit
Control
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 developed
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 location
Clear Registers - sets the values in all the registers to 0
Clear Memory - sets the values of all the memory locations to 0
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
Help
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 simulated
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 menu selection)
Next I - executes the next instruction (as the Next Instruction menu selection)
Run - runs the program to a halt instruction (as the Run menu selection)
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 selection
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 area
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, byte/character oriented
Hex - the data in this display is interpretted as hex numbers. Use only 2 hex digits, and
spaces between bytes.
sandsduchon.org/duchon/cs311/CompSim/helpSimulator.html 2/7
4/12/22, 2:26 AM HelpSimulator

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
Registers
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 and binary
Memory
Radio buttons 1, 2, 4, 8, 16 selects the number of words to show in each row. The memory
locations on the left are adjusted accordingly.
The main text area displays the current contents of the entire memory defined for this computer
in a scrolling text area.

Features: (top)
Computer defined by a text file
Will simulate the operations of a computer defined as a finite state machine
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 memory.
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

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.

Syntax:

sandsduchon.org/duchon/cs311/CompSim/helpSimulator.html 3/7
4/12/22, 2:26 AM HelpSimulator

keyword options Example


in first column
bus name <name>, size <size (dec)>, inputCount bus, name BUS, size 16,
<size (dec)> inputCount 7

name <name>, size <number of words (dec)>


ram ram,name M, size 4096 16
<bits per word (dec)>
register, name PC, size 16
name <name>, size <number of bits per word register, name AR, size
(dec)> 12, control LD INR CLR,
register
[, control [LD INR CLR] [, destination <name> destination BUS 1
<index>]
register, name OUTR, size
8, control LD

flag, name I
flag name <name> [, size <size (dec)>]
flag, name IEN, size 5

The keyword lines have no options. loadRam


Format of lines in between keywords:
10: 1234 ABCD
loadRam numbers in hex 30: FF01 00AA
endLoadRam first number is address
rest are values 100: 2107 7200
word by word
endLoadRam

setRegister, PC, 100


setRegister name, value (hex)

setFlag name, value (hex) setFlag, I, 1

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

helpComputer
The keyword lines have not options. <html><body>
helpComputer If first characters are "<html>", then the lines in ComputerSimulator
This computer is defined in
endHelp between the two flags are handled as html, Computer System
otherwise as plain text. </body></html>
endHelp

helpAssembler
<html><body>
helpAssembler ComputerSimulator
As helpComputer This computer is defined in
endHelp Computer System
</body></html>
endHelp

Assembler
The keyword lines have no options. Example
endAssembler
RTLinstructions
The keyword lines have no options.
endInstructions
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.
sandsduchon.org/duchon/cs311/CompSim/helpSimulator.html 4/7
4/12/22, 2:26 AM HelpSimulator

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:

Flag Explanation Example


s initial FSM state 00000, s, t 0, SC 0, IEN 0, R 0, S 1

h halt FSM state 00001, h, t 0, S 0


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

Conditions: (top)
Conditions use the following format:

c R [sb [eb]] [==|!=] v


where:
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
Examples:
c FGI == 1
c AC 15 == 0

Operations: (top)

Addressing:

Operations assign a new value to a register or memory location.


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.

sandsduchon.org/duchon/cs311/CompSim/helpSimulator.html 5/7
4/12/22, 2:26 AM HelpSimulator

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:

Function Comments Example(s)


++ increment the register by 1 SC ++
ALU_Set Set a register to a value R<0
ALU_Increment Increment the value in a register R<R+1
ALU_And AND the values in the left and right AC < AC ALU_And DR
parameters of the expression
ALU_Add ADD the values of the 3 parameters AC < AC ALU_Add DR E
ALU_RegisterMove Moves bits from one register to another AR < M AR
I < IR 15, CODE < IR 12 14,
AR < IR 0 11
ALU_Complement Computes the 1's complement of the first AC < AC ALU_Complement
(only) parameter
ALU_ShiftLeftWithCarry Circular left shift of 2 registers AC < AC
ALU_ShiftLeftWithCarry E
ALU_ShiftRightWithCarry 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.

sandsduchon.org/duchon/cs311/CompSim/helpSimulator.html 6/7
4/12/22, 2:26 AM HelpSimulator

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 names
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, 3
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

sandsduchon.org/duchon/cs311/CompSim/helpSimulator.html 7/7

You might also like