dcpu16py
dcpu16py copied to clipboard
support for "EQU" in assembler
Just like we have DAT (similar to the DFB in old 8-bit CPU assemblers) I think we need something like an EQU instruction in our assemblers for setting constants.
Has anyone seen an EQU equivalent in any of Notch's work (or in any other assemblers)?
What would it do?
It would set a label to the given value (rather than the memory location of the label)
So for example, you could set vidmem
to be 0x8000
once so your assembly code could just use vidmem
instead of 0x8000
.
basically, to avoid magic numbers in assembly code
for example, say I use 0x1000 to store the cursor. I'd rather write:
SET [cursor], vidmem
than SET [0x1000], 0x8000
Oh, assembler time definition, yeah, right. I have been working around it by using labels and dat allover the place (not fun over time, and slower)
yeah, labels + dat works but it adds a level of indirection
I looked trough most stuff that Notch put out and never notices anything like that, but I guess it will be added, as its nothing the CPU must do but rather the assembler.
Correct, it is an assembler feature common to many assemblers. I don't know if any DCPU-16 assemblers have it yet though.
We could add this with a prepended dot to make clear, that this is assembler specific:
.equ label value
Nearly every assembler uses this style to create his own extensions... btw. we can also add inclusion functionality; I guess that's something useful, too:
.include "file.asm"
another one to consider would be .org
to indicate where to put the code
Ah you mean some way of setting the base address? That would be sweet, yea.
btw, I just wrote a short proposal for the Standards Comittee about equ, let's see what they say: https://github.com/0x10cStandardsCommittee/0x10c-Standards/issues/27
(edit) As .org is something entirely different I created another proposal for this: https://github.com/0x10cStandardsCommittee/0x10c-Standards/issues/29
Update: Jarvix is, as far as I know, currently working on a RFCX about exactly this and some other stuff (conditional compilation and stuff like that)