The simple machine language simulator (smls) is an interpreter of a simple assembly language (developed for CPU lessons), it can be used as a starting point to learn an assembly language or introduction to programming. The language is described in [1].
Available instructions (Table from [1]):
Instruction/Mnemonic | Description |
---|---|
LOAD | Load the value of the operand into the Accumulator. |
STORE | Store the value of the Accumulator at the address specified by the operand. |
ADD | Add the value of the operand to the Accumulator. |
SUB | Subtract the value of the operand from the Accumulator. |
EQUAL | If the value of the operand equals the value of the Accumulator, skip the next instruction. |
JUMP | Jump to a specified instruction by setting the Program Counter to the value of the operand. |
HALT | Stop execution. |
This language uses a very simple CPU with only one Accumulator. Some instructions, like LOAD and ADD, use as an operand a memory address or a number; when operand is a number you need to put the character '#' before it (i.e. LOAD #30).
More info in [1].
LOAD #30 ADD #40 STORE 100
load 30 add 31 store 32
LOAD 60 SUB #2 STORE 60
% op-codes are case free load #1 store 20 add #1 store 21 add #1 store 22
load #0 store 49 % partial sum load #1 store 15 % tmp counter equal #11 jump #10 % jump to line 10 (jump ignore comment lines and empty lines) load 49 store 50 halt load 49 add 15 store 49 load 15 add #1 store 15 jump #5
First, you need to write the code. The code can be written in a simple editor, like nano or notepad (if you are using Windows), after that you can execute your code using smls. You can add comments to your program using the character % at start of line.
smls file
smls.exe file
By default, smls:
If this file exists in the current path, it will be read by smls.
Lines starting with % are ignored. 0 = disabled, 1 = enabled.
options:
m START END (show memory) [DEFAULT=none] This command displays the memory data between START END at the end of the program. You can use this command several times in config.txt a 0/1 (show the value of accumulator) [DEFAULT=0] t 0/1 (show the runtime) [DEFAULT=0] i 0/1 (show the lines of program that will be executed) [DEFAULT=1] lang auto/pt/en (the language of program) [DEFAULT=auto] sln 0/1 (show line number) [DEFAULT=0] If this option is equal 1 the user program will be only printed on the screen and the program will not be executed; useful when you are using commands like EQUAL and JMP.
In [3] you can see an example of 'config.txt'.
The smls supports Linux/UNIX and Windows.
binary smls for Windows (installer: do not need admin rights) (MD5 2c4098171d6f13566be0b8f05a48b98d)
binary smls for Debian/Ubuntu 32 bits (MD5 dc1caddc76cf3a08f0a2e77ad7abadfc)
binary smls for Debian/Ubuntu 64 bits (MD5 dffc22e39d7c85e8689217af3ce26509)
source code (MD5 960799d4479bddd6d15414c09c341e32)
To use smls in others systems, get the source code and compile it.
Before start using this program with your students, I recommend:
Prepared exercises: If you are a teacher I can send to you some exercises to you use in your class, just mail me.
Instruction/Mnemonic | Op-code | Description |
---|---|---|
LOAD | 001 | Load the value of the operand into the Accumulator. |
STORE | 010 | Store the value of the Accumulator at the address specified by the operand. |
ADD | 011 | Add the value of the operand to the Accumulator. |
SUB | 100 | Subtract the value of the operand from the Accumulator. |
EQUAL | 101 | If the value of the operand equals the value of the Accumulator, skip the next instruction. |
JUMP | 110 | Jump to a specified instruction by setting the Program Counter to the value of the operand. |
HALT | 111 | Stop execution. |
Number bit: if equal 1, the operand is a number (Image from [1]).
Please send me a mail.
Marcos Talau (talau@users.sf.net)
[1]
Osman Balci; William S. Gilley; Robin J. Adams; Emre Tunar; N. Dwight Barnette
http://courses.cs.vt.edu/csonline/MachineArchitecture/Lessons/CPU/Lesson.html
[2]
LOAD #10 STORE 0
[3]
%%% Lines starting with % are comments %%% Options: 0 = disabled, 1 = enabled %% will show the memory data between 0 100 at the end of program %m 0 100 %% 1=show the value of accumulator (default 0) %a 1 %% 1=show the runtime (default 0) %t 1 %% show the line numbers of program and exits, command useful when you %% are using commands like EQUAL and JMP (default 0) %sln 1 %% 0=not show the lines of code (default 1) %i 0 %% the language of this program (default auto) %lang en %lang pt