Re: the adress register, is good choice ?
- From: "Jeff Fox" <fox@xxxxxxxxxxxxxxxxxxx>
- Date: 29 May 2006 11:11:30 -0700
There are six words in the A set, different people use different names,
I think they need to be distinguishable from @ and !
a! A store, store T into A
a@ A fetch, fetch T from A
!a store A, store from T into memory using A as a pointer
!a+ store A plus, store from T into memory using A as a pointer and
increment A
@a fetch A, fetch from memory pointed to by A into T
@a+ fetch A plus, fetch from memory pointed to by A into T and
increment A
Thus traditional fetch and store are
: ! ( n a -- ) a! !a ;
: @ ( a -- n ) a! @a ; \ @ and ! could be two work macros as well
So fetch and store can always be used in a traditional way.
And A provides no problem not present in traditional or standard Forth.
There is no reason to dislike the option of having access to what
is actually inside of traditional @ and !. (other than it was rejected
from consideration for the standard almost twenty years ago.)
If you choose to reduce the overhead by taking advantage of
breaking of the @ and ! atoms into smaller particles you can
take advantage of how they cache the pointer, and free the
bottleneck in T. But of course if you choose to use A as a
pointer cache you can replace something like this ANS Forth
( n a -- a+cell ) dup >r ! r> cell+
with code where you don't need the address cached in T
using A and just write
( n ) !a+ \ a+cell
(And if you want to try to understand the logic behind this
design decision picture that with a simple and efficient
implemention it will mean that the code will be 8 times
faster and 10 times smaller by doing it this way. This
will only make some code that much smaller and faster.)
Of course if you have another task, it might need its own contents
in T or its own contents in A and its own contents in PC and R etc.
So you are going to have to deal with that whether you put the
address in T or in A or B or R. Taskers have to do that.
Likewise
A word that uses A can't call another word that uses A unless that
word uses A in a cooperative way with the first word or does a
save and restore. The cooperative approach is what is normally
used when things have to be fast, and save/restore is used
when other code might not cooperate direclty.
This is true whether you use A as temporary storage or as a
cached pointer. It is about cooperative software and what a
multitasker will need to save-restore based on what resources
you use in an implementation.
Since it may also be useful to have more than one pointer cached
F21 had !r+ and @r+ instructions. This made it a little like DOES>
when using the top of the return stack as a memory pointer. It is
also why c18 has B has a second pointer register.
Otherwise when using more than one pointer you have swap pointers.
Of course that is true of traditional Forth also, and it is an
improvement
over having to keep copies of multiple pointers and juggle them into T
along with the data that you are trying to get in and out of T at the
same time.
Of course if you want to do that with @ and ! in a traditional
way then the A register makes absolutely no difference.
Try to understand that there was always an A register. You
just never had direct access to it. The change in Forth almost
twenty years ago was just about giving the programmer
access to the insides of @ and ! if they wanted it, it doesn't hurt
anything except the notion that @ and ! were already perfect.
I think you have described a broken tasker. If it failed to change
the program counter or the stack you would see similar problems.
And finally, asking questions about colorforth in comp.lang.forth
won't reach many colorforth users, the mail list will tend to stay
more on-topic.
.
- References:
- the adress register, is good choice ?
- From: pablo reda
- the adress register, is good choice ?
- Prev by Date: Re: Counting bits set (again)
- Next by Date: Re: Forth Licensing Terms
- Previous by thread: the adress register, is good choice ?
- Next by thread: Re: the adress register, is good choice ?
- Index(es):
Relevant Pages
|
Loading