6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 8:22 pm

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: using TO
PostPosted: Thu Jul 30, 2020 3:48 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I would like to define "TO" to copy a value from a memory address to a variable. I believe the default is

fromADDR TO toADDR

instead of

fromADDR toADDR TO


If the first example is correct, by the same analogy one can get a string after a word command using "BL WORD" or "QUOTE WORD"

Is there a way to get the address of "toADDR" after the word command "TO"?

Currently my definition of "TO" is (but only works for the second example)

: TO SWAP @ SWAP ! ;


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Fri Jul 31, 2020 6:18 pm 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 255
This depends a lot on how you variables are implemented in your forth.
I would use ' (the single quote - sometimes called "tick") to get the XT (execution token) of the variable. It reads the next name at the input (which is what I believe you are trying to figure out how to do), looks it up, and puts that word's XT on the stack. If you use ' in a new word's definition, it will do this action when the new word is run.

Note that the XT isn't the address of the DATA in the variable, but rather is the address of the ROUTINE to run when the variable name is used. This routine normally puts the address of the data on the stack.

In TaliForth2, the routine is just a JSR (3 bytes long - Tali2 is an STC forth) and the data comes right after that JSR, so if I can get the XT using ' then I can just add 3 to get the location of the data. That means, for TaliForth2, you could write a version like:

: TO ' 3 + ! ;

Note that the above places a VALUE into a variable (the standard behavior for the word TO). If you want to copy from one variable to another, you just have to get the data from the source variable first. That might look like:

: COPYTO @ ' 3 + ! ;

Your variables may be implemented differently, but often the data is right near the XT and you can just add the offset (as I did above) and then store your new value.


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Sat Aug 01, 2020 4:35 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Thanks!

For some reason I got it in my head that the tick didn't work in word definitions. But that works.

BTW. What does XT stand for?

I have only read tick as pointing to the PFA (Parameter Field Address).


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Sat Aug 01, 2020 5:28 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
IamRob wrote:
For some reason I got it in my head that the tick didn't work in word definitions. But that works.

The only such limitations I can think of offhand are the IMMEDIATE compile-only words which cannot be used in interpretation mode, like DO...LOOP, BEGIN...UNTIL, etc..

Quote:
BTW. What does XT stand for?

"execution token," usually a word's CFA. (Caveat: I have not thought about how some of these things would work in a STC Forth.)

Quote:
I have only read tick as pointing to the PFA (Parameter Field Address).

Tick looks up the CFA.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Mon Aug 03, 2020 4:37 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
That could be why I am having trouble using it.

I confirmed that under the Forth I am using, it is returning the PFA.

Just another thing to add to the list to fix.


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Mon Aug 03, 2020 5:15 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Worth checking. With FIG Forth, at least, it's the PFA that's left.

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Mon Aug 03, 2020 6:49 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
Dr Jefyll wrote:
Worth checking. With FIG Forth, at least, it's the PFA that's left.

Ah yes. I forgot about that possibility. I just checked. FIG does return the PFA. Strange. 79 and 83 return the CFA.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Tue Aug 04, 2020 4:32 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
That is what is messing me up, in some of the primitive words, the code is not following the CFA.

Which means the PFA of some words are actually the word-length indicator of the next word.

Having the tick point to the CFA does make more sense.


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Tue Aug 04, 2020 5:00 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
In the '02 ITC Forth I've worked with (and I think Brodie's book agrees), plus my '816 Forth, a primitive's CFA points to the beginning of the machine code. That's usually in the parameter field. However, the CFA may point elsewhere if the desired code already exists in another word's code definition so you can save memory by pointing to that instead of repeating it. So in that latter case, yes, what might appear to be the beginning of the parameter field would actually be the first byte of the name field of the next word.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Wed Aug 05, 2020 3:23 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Right.

But since, in Fig Forth anyways, the tick points to the PFA and not the CFA, this makes the tick useless for some words.


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Wed Aug 05, 2020 12:36 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Not really. It's easy to get the cfa, at least in FIG Forth. The word CFA takes a pfa and returns the corresponding cfa. So, you simply choose to use either tick, or tick followed by CFA, to get what you want.

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Thu Aug 06, 2020 8:52 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
It's not so much a matter of "to get what you want", but more to understand when to use the CFA or the PFA.

I have come across a few words that require the address of the CFA, but have yet to really see any substantial requirement for the PFA.

Any examples where the PFA might be required would be appreciated.


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Thu Aug 06, 2020 9:19 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
IamRob wrote:
Any examples where the PFA might be required would be appreciated.

In the case of a variable that you would want to use in assembly language when you're writing a Forth primitive, ISR, runtime, etc., you'll want assembly-language instructions to access the data field, ie, the parameter field, not the code that puts its address onto the stack. This is of course if the variable is entirely in RAM. If it's in ROM, the data space cannot directly follow the code field, for obvious reasons, so different rules apply.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Fri Aug 07, 2020 4:46 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
GARTHWILSON wrote:
IamRob wrote:
Any examples where the PFA might be required would be appreciated.

In the case of a variable that you would want to use in assembly language when you're writing a Forth primitive, ISR, runtime, etc., you'll want assembly-language instructions to access the data field, ie, the parameter field, not the code that puts its address onto the stack. This is of course if the variable is entirely in RAM. If it's in ROM, the data space cannot directly follow the code field, for obvious reasons, so different rules apply.



My bad! Didn't finish my sentence.

All these good examples are programmed into my Forth and nothing extra is required to use them.

I meant to say "Any examples where the PFA might be required with the use of the tick".


Top
 Profile  
Reply with quote  
 Post subject: Re: using TO
PostPosted: Tue Mar 02, 2021 3:19 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
GARTHWILSON wrote:
IamRob wrote:
Any examples where the PFA might be required would be appreciated.

In the case of a variable that you would want to use in assembly language when you're writing a Forth primitive, ISR, runtime, etc., you'll want assembly-language instructions to access the data field, ie, the parameter field, not the code that puts its address onto the stack. This is of course if the variable is entirely in RAM. If it's in ROM, the data space cannot directly follow the code field, for obvious reasons, so different rules apply.


Since STATE is off ( interpreting state) during assembly and a variable returns the address of its data field, you don't even need ' ( tick) for this purpose.
Code:
VARIABLE FOOBAR

CODE FOO
    .
    .
    .
   LDA_ABS  FOOBAR ,
   ORA_ABS  FOOBAR 1+ ,
    .
    .
    .



Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: