Re: the adress register, is good choice ?



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.

.



Relevant Pages

  • Re: void *
    ... A container that can store any kind of object, ... If you want to *store* objects in the linked list, as you say, then ... One of the code snippets Roman ... would result in a pointer to somewhere where the number 100 ...
    (comp.lang.c)
  • Re: What is a sequence point?
    ... and the store to a only depends on the value stored in b being calculated ... If they all have the same types, any self-respecting optimizing compiler ... will load the value once and store it twice without doing anything else ... load a1,a;Load location to store word pointer ...
    (comp.lang.c)
  • Re: GetOpenFileName filters not working
    ... store a pointer with each window and store all of the unique data you want. ... HWND hWnd; ...
    (microsoft.public.win32.programmer.ui)
  • [6/6] sparsemem hotplug base
    ... allows sparse mappings to be created after boot in a hotplug ... The section_mem_map doesn't really store a pointer. ... There are a couple of things I'd like to store about a section. ... struct mem_section { ...
    (Linux-Kernel)
  • Re: set!, mutation or rebinding?
    ... an memory adresses, where the "contents" of the value is stored. ... pointer, and then go on from there to store other "small" types ... tag of 1 and so on -- and store or fetch values with shift and mask ... So it works in code that the system sees {integer tag} ...
    (comp.lang.scheme)

Loading