6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 7:59 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun Jan 22, 2023 12:41 am 
Offline

Joined: Mon Jan 09, 2023 9:33 pm
Posts: 29
A war question in Forth is which is the safe size of parameter stack in cells.

I did like to ask how deep the (parameter) stack goes in common standart(s) words.

Using a 6502, usually the stack uses X index at page zero and grows deep as decreasing from 0xFF,

Could someone test on the Forth you're using?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 22, 2023 1:16 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
agsb wrote:
Could someone test on the Forth you're using?

In my treatise on 6502 stacks (plural, not just the page-1 return stack), there's a page addressing this: http://wilsonminesco.com/stacks/enoughstackspace.html .  The depth of stack usage is not a much as many people fear.  The stacks treatise is not specifically about Forth, but I mention Forth in it frequently, and show how to do assembly language in a very Forth-like way (with a ZP data stack) without necessarily using Forth.

_________________
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  
PostPosted: Sun Jan 22, 2023 5:45 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895

The data stack on my Forth can hold 48 items before the stack checking word ?STACK aborts with the message "STACK FULL!" .
Since the stack is normally only checked while interpreting or compiling and not in every word, there are another 14 cells beyond this for an overflow buffer.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 27, 2023 8:19 pm 
Offline

Joined: Mon Jan 09, 2023 9:33 pm
Posts: 29
Moore uses 22 or 19 in Novix chips


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 30, 2023 11:11 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
I've tried to make my Forth's data stack as large as possible; however, it is on a Commodore 64 so the data stack has to share zero page with the C64's kernal as well as Forth's virtual machine registers.
A recursive algorithm can use up stack space very quickly. It's been my experience that the data stack grows just as fast or faster than the return stack. Stack checking could be added to some recursive algorithms without too much of a speed penalty.
Multitasking where each task gets a section of the stacks may also require large stacks.


Top
 Profile  
Reply with quote  
PostPosted: Mon May 01, 2023 2:13 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
In normal usage, the main thing I can think of that could take a lot of stack space is the process of compiling (not running) a large CASE structure, ie, one having a ton of OFs.  (I do have the of internal, which is compiled by OF, so it's far more efficient than doing a ton of nested IF...ELSE...THENs.)

I also have SET_OF which lets you put a set of numbers on the stack to compare something to all in one line of the CASE structure.  The following is from a text file that acts kind of like shadow screens for the main assembly-language source code for my '816 Forth:

Code:
\ The idea for SET_OF below is from FD, May/Jun '97.  It's nice for situations
\ where you want something like

   DUP  14 =
   OVER 15 = OR
   OVER 18 = OR
   OVER 20 = OR
   OVER 25 = OR
   OVER 65 = OR
   IF bla bla bla ELSE ...

\ but in a CASE statement.  Normally in a case statement, you'd have to test for
\ each of these numbers, and then have the same code between the OF and ENDOF
\ that follows each.  You can't give OF more than one number to compare to, so
\ SET_OF takes care of that.  The situation above now all fits on the first OF
\ line of the example

   CASE
      { 14 15 18 20 25 65 } SET_OF   bla bla bla   ENDOF
                  <...>         OF      <...>      ENDOF
                  <...>         OF      <...>      ENDOF
      if-no-match-then-do-this-other-stuff
   ENDCASE

\ SET_OF allows a type of OF that can compare to several possible values that
\ can result in the same action.  The values can be literals, or they can be
\ fetched or calculated between the { and the } .   set_of is the internal
\ compiled by SET_OF.

\ Notice that { and } are not limited to have only literals between them.  You
\ can just as easily have some of the values calculated on the fly, as long as
\ you keep in mind that the number of comparisons that will be made by SET_OF
\ will be the difference between the stack depth immediately before } minus the
\ stack depth at { .  You cannot, for example, remove a previously existing cell
\ from the stack to calculate one of the comparison values unless you
\ specifically take action to correct the resulting stack-depth discrepancy.



: set_of                \ Syn: { 13 16 20 24 } SET_OF ... ENDOF       (internal)
   DUP 1+ PICK          \ Copy the argument that went into CASE
                        \ ^ arg T1 T2 ... Tn n arg
   FALSE  ROT 0         \ ^ arg T1 T2 ... Tn arg FALSE n 0
   DO                   \ 1st time into loop: ^ arg T1 T2 ... Tn arg FALSE
      OVER 3ROLL = OR
   LOOP                         \ After last loop: ^ arg arg flag
   ?EXIT   NOT          ;       \ If flag was false, change one copy
                                \ of arg so they don't match.


\ SET_OF works very much like OF .  It does not make sure you preceded it with
\ { ... } .  I may decide to add that to the compiler security in the future.


: SET_OF   ( CASECODE n -- CASECODE ADR n+1 OFCODE )        \   (FD May/Jun '97)
   ?COMP                                                    \ Related:  RANGE_OF
   >R R@ PICK 6 ?PAIRS
      COMPILE set_of  COMPILE of
      HERE 0 ,
   R> 1+     7          ;       IMMEDIATE


It might not be thoroughly tested in my '816 Forth (which I've paid very little attention to in years), but I've used it in my '02 Forth.  In many places in the text file that acts kind of like shadow screens for the assembly-language files, I have the Forth equivalents for things that are actually implemented in assembly language.

_________________
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  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 21 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: