vasm.py: a mini-assembler for vCPU code
Posted: 08 Apr 2020, 13:38
I always wanted a stand-alone vCPU assembler that can produce .gt1 files. But I didn't want to put effort in writing a front end. So I took the principles from Core/asm.py and created Core/vasm.py. This is (the back end for) a symbolic vCPU assembler. For reference, with 103 lines it is smaller than gtemu.c, although that wasn't a goal.
As with asm.py, the idea is that you use Python syntax as your front end notation. We experimented a bit so that we can now fake indentation, a well-known problem of using Python for this purpose. The extension for these programs is .vasm.py . As an example, here is Blinky2.vasm.py:
You then create a .gt1 file with:
It disassembles as expected:
This may be useful for those who don't want to learn GCL, but just want something light and semi-familiar. Don't forget you have all the power of Python at your finger tips, so you have macros with `def' and can evaluate expressions.
Bug reports and feature requests through GitHub please. I can foresee some tweaks, but I don't aspire to turn this into a castle.
As with asm.py, the idea is that you use Python syntax as your front end notation. We experimented a bit so that we can now fake indentation, a well-known problem of using Python for this purpose. The extension for these programs is .vasm.py . As an example, here is Blinky2.vasm.py:
Code: Select all
# Please build this from the Makefile
from vasm import *
p=0x30 # User variables start from $30 in zero page
ORG(0x200) # User programs can start from $200
- LDWI(0x800) # Top left pixel
- STW(p) # Pointer variable p
L('Loop'); POKE(p) # Update pixel
- ADDI(1) # Increment vAC
- BRA('Loop') # Loop forever
END(0x200) # Execution start address
Code: Select all
$ make Apps/Blinky/Blinky2.gt1
Code: Select all
$ gt1dump.py -d Apps/Blinky/Blinky2.gt1
* file: Apps/Blinky/Blinky2.gt1
0200 11 00 08 [vCPU] LDWI $0800 |...|
0203 2b 30 STW $30 |+0|
0205 f0 30 POKE $30 |p0|
0207 e3 01 ADDI 1 |c.|
0209 90 03 BRA $0205 |..|
* 11 bytes
* start at $0200
Bug reports and feature requests through GitHub please. I can foresee some tweaks, but I don't aspire to turn this into a castle.