Pages: 1
|
 |
|
Author
|
Topic: "if" short jump fix (Read 2837 times)
|
Alexey Abramov
Library Contributor
Jr. Member
  
Karma: +0/-0
Offline
Posts: 47
YO! Forth Forever!
|
My code:
: if $c009 2, m: drop $840f 2, here 0 , ; : (if) $063b 2, m: drop m: drop $0f 1, 1, here 0 , ; : <>if $84 m: (if) ; : =if $85 m: (if) ; : <if $8e m: (if) ; : >if $8d m: (if) ; : ?if $063b 2, $820f 2, here 0 , ; : then dup here swap - 4 - swap ! ; : else $e9 1, here 0 , swap dup here swap - 4 - swap ! ; Now You can nesting many code in "if/else/then" blocks!
|
|
|
|
|
Logged
|
|
|
|
Charles Childers
Administrator
Sr. Member
    
Karma: +2/-0
Offline
Posts: 745
|
Out of curiosity, has anyone run into problems with the short-jump form of "if" that's currently used in RetroForth? If so, can you share the code that needs a longer form? I'd like to know if this is actually a bug before I switch to using long jumps in the conditional words.
|
|
|
|
|
Logged
|
|
|
|
ron
Contributor
Full Member
   
Karma: +0/-0
Offline
Posts: 88
|
Reva figures out whether to use a short or long jump, so it's (supposedly) using the fastest/smallest instruction.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ron
Contributor
Full Member
   
Karma: +0/-0
Offline
Posts: 88
|
Ouch! 
Yes, I was thinking about my loop stuff. The 'if' etc. fix up the condition and patch in 90h "nop" codes - but actually it might be faster to do the long jump rather than short jump; nop; nop; nop ...
Of course, one could realize a short jump was needed and then move the code block over three bytes - which would not be a big gain overall unless the code were executed enough times.
|
|
|
|
|
Logged
|
|
|
|
ron
Contributor
Full Member
   
Karma: +0/-0
Offline
Posts: 88
|
Actually, nevermind ... my 'if' code doesn't try to be jump-size smart - only the looping constructs (loop, while) do.
|
|
|
|
|
Logged
|
|
|
|
Pages: 1
|
|
|
|
|