I'll add another note. My
6502 stacks treatise has
Appendix A which is a big start on a STC Forth, intended for someone who wants to be able to do assembly language in a very Forth-like way without necessarily using Forth. (I say "big start" because although the stacks treatise was finished and posted a couple of years ago, I never finished this appendix. It should still save you a substantial amount of work though.)
The following paragraphs are a slight tweak of the text at the top of that file.
The material there is much of what you would need to do a subroutine-threaded code (STC) '02 Forth. It has the stack operations for simple math, logic, memory, strings, etc., and if I ever get around to finishing it, it will also have things like trig, log, square-root functions. I've added another major feature to the site after I posted the stacks treatise, and the next major one will probably be my '816 Forth. Your work on your '02 STC Forth, if you share it russellsprouts, may help me finish up this Appendix A.
What it is primarily missing for doing a STC Forth is the components for doing its own compiling and for interpreting command lines (since there are no headers here for
WORD to find the addresses of various routines), and compiling the control structures.
ZP data stack cell size throughout is 16 bits, ie, two bytes. Double-precision numbers take 32 bits, or two cells of two bytes each, ie, four bytes total. Characters or bytes still take 16 bits, but the high byte is zeroed.
For individual cells, byte order is the same as 6502: low byte first. For double-precision numbers, the low cell is pushed onto the stack, followed by the high cell. So if you have a double-precision number that's small enough to fit in a single cell (without changing the sign), you can convert the double to a single with just
DROP (in fact,
StoD uses the same code).
Most of these get much shorter on the 65816 since it is far more efficient at handling 16-bit quantities. 816StackOps.ASM (Appendix B) is planned for that. Right now there's just a placeholder file for it.
Have an 8-byte section of ZP called
N, for routines' temporary storage.
N-1 is also used, so don't have something else coming right up to
N.
N is introduced 80% of the way down the page in section 4 of the stack treatise on virtual stacks.