About fetch/store operations, and the terminology: In Forth with 16-bit cells, we're familiar with
@ and
! (fetch and store) as well as
C@ and
C!. They all accept an address from a 16-bit cell on stack, but the
data moved by
C@ and
C! is only byte-wide, even though it's moved to or from a full-width cell on stack. (The high-byte of the cell is ignored by
C! and padded to zero by
C@.) When you have 32-bit cells the word set needs two new members. The fetch/store words could be named as follows:
- @ W@ and C@ fetch 32-, 16- and 8-bit values, and
- ! W! and C! store 32-, 16- and 8-bit values.
The convention -- and this is a matter of preference -- is to name the full-width word as simply as possible ( example:
@ ), and to embellish the name for special cases. Example:
C@ and
W@ are special because they don't handle full-width data. Special names for special functions.
The same can apply in regard to addresses. IOW, the names
@ and
! can be taken to mean a full-width address is used. If you want comparable words that only use a 16-bit address they'd be called
LOCAL@ and
LOCAL! or something along those lines (suggestions welcome). They'd still accept an address from a 32-bit cell on stack, but the high word would be ignored because it's implicit that Bank 0 will be used.
Notice I've chosen to deem 16-bit addresses "special" and to name the corresponding words accordingly. When you open the door beyond 64K you'll have to either patch an extension on your existing naming conventions or else use names that embrace the new (virtual) machine. The decision depends on whether you'd rather have source code that leans toward compatibility with legacy code, or toward compatibility with Forths that run on native 32-bit processors.
Fetch and store could each end up with as many as six variations, so let's be careful to be specific when discussing these. The combinations (where full-width is considered non-special) could be called:
- @ W@ and C@ use a full address and fetch 32, 16 or 8 bits of data
- LOCAL@ LOCALW@ and LOCALC@ use a 16-bit address and fetch 32, 16 or 8 bits of data
- ! W! and C! use a full address and store 32, 16 or 8 bits of data
- LOCAL! LOCALW! and LOCALC! use a 16-bit address and store 32, 16 or 8 bits of data
Footnote 1: I've mentioned "full width" addresses taken from 32-bit cells. But we know on '816 only 24 bits can be used. The top 8 bits will be ignored.
Footnote 2: for a Forth that's expected to deal predominantly with 32-bit data accessed in a 24-bit space it's worth considering abandoning X and the ghost stack and instead using D (the Direct register) as the data-stack pointer. Despite certain drawbacks, D offers the highly compelling ability to access a 24-bit indirect pointer in situ on "stack"
and apply post-indexing via Y -- which is what lets you easily access more than 16 bits of data. (I'm not the only one to come up with the D-as-SP idea; I recall seeing it mentioned by one of the SBX users.)
@Garth, the RStack actually
can be efficiently given a ghost, using the 816's d,s (ie; stack-relative) address mode. The d (ie: displacement) in d,s is only 8-bit, but that'll suffice.
@Mike, it's true a ghost stack has many uses beyond extended addresses. Floating-point and perhaps even strings are also possibilities, especially if space for extended ghosting is provided. IOW cells could be allowed to be even larger than 32-bit. Words that don't need the extra space just ignore it.
-- Jeff