Quote:
The stack pointer is fetched by the word 'S (pronounced tick-S).
Since 'S provides the address of the top stack location, the phrase
'S @
fetches the contents of the top of the stack. This operation, of
course, is identical to that of DUP.
Since 'S provides the address of the top stack location, the phrase
'S @
fetches the contents of the top of the stack. This operation, of
course, is identical to that of DUP.
The Forth-83 Standard has this entry for SP@ .
Quote:
SP@ -- addr 79 "s-p-fetch"
addr is the address of the top of the stack just before SP@
was executed.
addr is the address of the top of the stack just before SP@
was executed.
The Forth-83 Standard makes no mention of the data stack pointer, only that SP@ fetches the address of the top of the stack just before SP@ was executed.
My Forth also has RP@ and AP@ . AP@ fetches the address of the top of the auxiliary stack. The phrase
AP@ @
fetches the contents of the top of the auxiliary stack. This operation is identical to that of A@ .
whether SP@ and AP@ can be thought of as fetching the address of the top of their respective stacks or fetching the stack pointer for their respective stacks doesn't really matter, the result is the same.
The exception, at least on the 6502, is RP@ . If the phrase
RP@ @
fetches the contents of the top of the return stack then RP@ does not fetch the return stack pointer, it fetches the return stack pointer plus 1. If RP@ does fetch the return stack pointer then the phrase
RP@ @
does not fetch the contents of the top of the return stack.
Which should it be? Should RP@ fetch the return stack pointer or the address of the top of the return stack?
Although the Forth-83 Standard mentions SP@ , it makes no mention of RP@ .
I personally think RP@ should fetch the address of the top of the return stack, which means the phrase
RP@ @
would fetch the contents of the top of the return stack. This operation would be identical to R@ .