SamCoVT / TaliForth2

A Subroutine Threaded Code (STC) ANSI-like Forth for the 65c02
Other
29 stars 6 forks source link

Shrink assembler with more homogenous SAN notation? #128

Open patricksurry opened 2 months ago

patricksurry commented 2 months ago

While working on #127 I wondered about refactoring the assembler as a set of base mnenomic forth words plus separate qualifiers which could be parsed directly by the assembler.

From a user perspective that would mean writing $42 adc .# rather than $42 adc.# but would shrink the assembler-wordlist significantly (about 64 base mnemonics vs current 177) with a big associated saving in lookup table, header and repeated text storage (e.g. one copy of the string ".zx" rather than eighteen now).

I think this would save another 1.5-2Kb on binaries that include the assembler/disassembler. One challenge is that SAN 16 bit addressing doesn't have an explicit 16bit address qualifier, e.g. adc in SAN means adc llhh so it would be hard to distinguish between $42 adc .# and $42 adc.

A possible solution would be to require an explicit 16 bit address qualifier like .w which would make SAN more homogenous and (imho) more readable. See below for adc example. Each base mnemonic would either always (e.g. adc) or never (e.g. phx) include a qualifier. The full list of possible qualifiers would be something like .#, .a, .w, .wi, .wxi, .wx, .wy, .z, .zi, .ziy, .zx, .zy, .zxi.

Traditional | SAN
adc #dd     | adc.#  
adc llhh    | adc   => adc.w
adc llhh,x  | adc.x => adc.wx
adc llhh,y  | adc.y => adc.wy
adc zp      | adc.z 
adc (zp)    | adc.zi 
adc (zp),y  | adc.ziy
adc zp,x    | adc.zx
adc (zp,x)  | adc.zxi