From: Erich W. <ew....@na...> - 2010-08-08 06:52:11
|
Hi Leon, [Q] Does "here" point to flash or ram? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Prior to amforth version 4.0 here points to the next available location in flash memory and heap points to the next available location in RAM. Starting with version 4.0 here points to the next RAM location and dp points to the next flash location This is in the release notes of amforth 4.0 on the web page http://amforth.sourceforge.net/ > core: ANS94 mention that HERE points to the data (RAM) region. > Re-introduced DP as the dictionary (Flash) pointer. > HEAP is gone. > Migrate old HEAP to HERE and old HERE to DP. The migration effect is readily visible when comparing the files variable.asm diff -uw releases/3.9/core/words/variable.asm trunk/core/words/variable.asm --- releases/3.9/core/words/variable.asm 2010-06-02 11:33:51.000000000 +0200 +++ trunk/core/words/variable.asm 2010-07-02 21:16:41.000000000 +0200 @@ -12,7 +12,7 @@ .dw XT_DOCREATE .dw XT_COMPILE .dw PFA_DOVARIABLE - .dw XT_HEAP + .dw XT_HERE .dw XT_COMMA .dw XT_DOLITERAL .dw 2 So yes, there is unfortunately confusion and the answer depends on the version of amforth. [Q] How is variable and 2variable supposed to work? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "variable" is a location to hold a mutable piece of information. Thus the dicionary entry of a "variable" holds (in flash) a pointer to a RAM location. In a purely RAM based Forth (e.g. gforth) the definition : variable create> 0 , 0 , ; is perfectly adequate, because *everything* is in RAM anyway. In a flash based Forth as amforth the definition is more like : variable create> here , \ store addr of next avail. RAM 2 allot \ allot 2 bytes of RAM ; replacing 2 by 4 allocates 4 bytes indeed. However, the behaviour of the words involved in converting the character input (eg. "100.") into a double cell number must work consistently, too. I'm not an expert at this. The current definition of 2variable (trunk, verion 4.1) is found in trunk/lib/ans94/2x.frt : 2variable here 2 cells allot constant ; the value of "here" is put into a constant (flash) and thus points to the alloted RAM location. No need to use "create>". Nice! BTW that is how you create an array of arbitrary length. here 20 cells allot constant myArray (and yes, here used to be heap before version 4.0) Hope this helps. Cheers, Erich On 08/08/2010 05:17 AM, Leon Maurer wrote: > Would your just take the old definition of variable > (http://amforth.sourceforge.net/words/XT_VARIABLE.html) and replace > the 2 with a 4? > > A more general request: could someone explain how variable works? > > I understand how it works in the system from Staring FORTH, but not this one. > > In addition, I have two more specific (and possibly quite newbish) questions. > > I think some of my confusion is related to HERE. The front page says > it points to RAM. In (at least some of) the documentation of all the > words (http://amforth.sourceforge.net/words/) it looks like it's > pointing to Flash. Which is it? > > Also, why (CREATE) COMPILE COMPILE instead of CREATE? > -Leon > > On Sat, Aug 7, 2010 at 2:57 PM, pito<pi...@vo...> wrote: >> Hi friends, which one is the correct way to define 2variable in >> amforth: >> >> : 2variable here 2 cells allot constant ; >> : 2variable create 0 , 0 , ; >> >> Just to be sure we do not operate within the flash and thus we >> destroy it slowly...Pito. >> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by >> >> Make an app they can't live without >> Enter the BlackBerry Developer Challenge >> http://p.sf.net/sfu/RIM-dev2dev >> _______________________________________________ >> Amforth-devel mailing list >> Amf...@li... >> https://lists.sourceforge.net/lists/listinfo/amforth-devel >> > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Amforth-devel mailing list > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel |