tschak909 Posted April 5, 2021 Share Posted April 5, 2021 @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 Quote Link to comment Share on other sites More sharing options...
GarthW Posted August 3, 2021 Share Posted August 3, 2021 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.