Jump to content
IGNORED

[FORTH] proper way to iterate with offset?


Recommended Posts

@cas and anyone else who can answer:

 

I currently have a routine that needs to iterate from a known address for a certain # of bytes, and it uses a VARIABLE to keep track of the start of the buffer.

 

What is the correct way to implement this, as this probably is completely wrong:

 

SCR # 78 
  0 ( FLD - DISPLAY FILENAME FOR SLOT )
  1 
  2 ( uses CURRENT variable )
  3 
  4 : .FLD"      ( n -- )
  5     CURRENT C!
  6     38 2 DO
  7         CURRENT C@ FLDBUF
  8         I +
  9         C@
 10         HEMIT
 11     LOOP ;
 12 
 13 
 14 
 15 -->

is the right thing to do to use the return stack? I genuinely am not comfortable with doing that, for some reason.

 

-Thom

Link to comment
Share on other sites

  • 3 months later...

Does CURRENT get modified during the loop, by FLDBUF?  If not, you could forgo the use of the variable and just DUP it where it's needed in the loop, then get it off the data stack with DROP after LOOP.  Actually, to go further, if the DUP FLDBUF is going to always give you the same thing for any given time that .FLD" is called, why not do that just once, before you enter the loop, and put its result on the data stack, then do your DUP  I  +  C@  HEMIT  LOOP  DROP  ;  To further streamline things, if you use I + often enough, it's worth making it a primitive I+, and it might even be worth integrating more than that, like I+@.  Does the " at the end of the .FLD" name mean a string literal is supposed to follow in the source code?  Maybe there's too much here I'm not familiar with.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...