12.Assembler - mattsteeldue/vforth-next GitHub Wiki
Forth ASSEMBLER vocabulary
Zilog Z80, also Z80N ( Next extensions are available )
This vocabulary is imported via needs assembler (or 100 load if you use the standard blocks-file).
This is a tentative Z80 adaptation of Albert van der Horst's work available at https://github.com/albertvanderhorst/ciasdis. In particular I carefully studied the two Forth sources as80.frt and asgen.frt to get some clue to port his work to be effective within a "vintage" Sinclair ZX Spectrum system with a ZX-Microdrive. As far I can see, I used an older version than these above. You can recognize asgen.frt in screens between 100 and 119 and as80.frt in screens from 120. Screens 100-170 is where I keep the source of Z80 ASSEMBLER VOCABULARY.
The TASK involved here to modify Albert's 8080 assembler to be a Z80 assembler: my first aim was to build simply the assembler so I ignored the dis-assembler part and to reduce the overall size I also omit wide part of it.
First, I had to introduce some new xFAMILY, creative words
- CBFAMILY, for CB prefixed opcodes (shift, rotation and bit manipulation)
- EDFAMILY, for ED prefixed
- DDFAMILY, for IX index register specialized opcodes
- FDFAMILY, for IY index register specialized opcodes
Then, I modified the _COMMAER_s names to be
- N, for immediate single byte value
- NN, for immediate word value
- AA, for memory address value
- P, for port address value (16 bits)
- D, for displacement in relative jump JR.
Next, I renamed some single byte op-code to have a better near-Z80 notation. To avoid some Forth-Assembler name clash, I preferred to use some peculiar notation for some op-codes, for example EXAFAF EX(SP)HL EXDEHL instead of EX AF, AF' EX (SP),HL EX DE,HL
Also, I preferred to explicitly say A for all arithmetic/logic opcodes, e.g. ANDA r| instead of AND r and so on. IX and IY index-register caused the most trouble because they add both a prefix and (often) a displacement and because they can be used in conjunction with CB prefix. In this case I use some custom late-compilation words to fix everything but then relaxing some of the syntax check that the Albert's core provided.
Z80N extensions are all ED-prefixed, so I followed the same path introducing a new COMMAER to enforce a better syntax check.
LH, used by PUSHN to compile a big-endian argument