A Python OISC emulator and assembler using Subleq
whisk_asm_2.py reads the assembly source file input.sla and writes the assembled output to output.slq.
whisk.py can the be run which will read the source in output.slq and run it.
I created my own assembly syntax for this project using various conventions from different places. The following is a list of commands that can be used:
s a b c
is the standard subleq operation. The value ata
is subtracted from the value atb
and stored atb
. If this value is less than or equal to zero, the code will branch to adressc
.b
can be an adress (15
) or a variable ($name
).c
can also be a label (:here
) anda
can also be a label or literal (!42
).add a b
will add the value at a to that at b. The arguments can be addresses or variables, anda
can be a literal.inc a
ordec a
will increment or decrement the value ata
.jmp a
will jump to the address or labela
.cpy a b
will copy the value ata
tob
.:here
declares a label that can be jumped to later.print a
prints the value at a to console.$name = a
assigns the valuea
to the variable with name$name
.
- A general rule here is that you can never have a literal as the second argument to a statement as this will change the stored value of that literal and is therefore not allowed.
- The symbol
?
can be used to specify a jump to the next command with ans
statement meaning no conditional branching will occur, e.g.s !10 $value ?
.
Happy Coding!