2 ms·
I did something similar when I needed to make an assembler for a web based IDE. Since I was writing an assembler anyway, and I had no particular requirement to
by Lerc 4y ago
I did something similar when I needed to make an assembler for a web based IDE.
Since I was writing an assembler anyway, and I had no particular requirement to be compatible with existing assemblers, I got to play around with the mechanics of macros.
I created a directives
.snip <name>
.endsnip
and
.use <name>
to create a kind of inline module mechanism where snippits of code could be included if the code contained a .use with the same name. Multiple instances of .use would cause the snip to only be included once.
Combining snips with macros meant you could have a macro available and it could add supporting code on demand via .use.
Here's a gist loaded into the IDE
https://k8.fingswotidun.com/static/ide/?gist=ad96329670965dc023c5ae740b433ad6 https://k8.fingswotidun.com/static/ide/?gist=ad96329670965dc...
The three Lines after init: Are all macros doing quite a bit of behind the scenes work.
init:
set_stack_pointer RAMEND
load_let_values
print_rom "Mode0 Text"
print_rom needs to reserve a space in the ROM for the text, and call a print routine with the pointer to the text.
The print routine has variables to indicate where the current cursor position is, where in memory the text buffer is etc. These are set up with macros
letw mode0_Page,$8000
letb mode0_Width,80
letb mode0_Height,60
letb mode0_CursorX,0
letb mode0_CursorY,0
letb mode0_Color,$20
Which allocate ROM space for the initial values and set the symbols to indicate their RAM position. The macro load_let_values inserts the code required to transfer the ROM initial values into their ram locations.
In hindsight, I probably shouldn't have made an assembler a line-by-line processor, there are a bunch of nesting things that I think would have some tough jobs easier.
Anyway, if anyone wants a idiosyncratic AVR macroassembler that no one asked for it's on github https://github.com/Lerc/AvrAsm https://github.com/Lerc/AvrAsm