Does anyone have an example of a case flow control structure using FF on Scamp3 or any other implementation. A series of dup if then could do it but don't know which runs better.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is the build of a case flow I use. I had to modify it slightly in order to use the for ... next construct.
\ ***********
\ Case for FlashForth *
\ Filename: build-case.ff (voorheen case.txt) *
\ Date: 26.01.2014 *
\ FF Version: 5.0 *
\ Copyright: Mikael Nordman *
\ Author: Mikael Nordman edited by FZ *
\ **********
\ FlashForth is licensed acording to the GNU General Public License
\ *************
\ A case implementation posted by Jenny Brien on c.l.f.
\ Modified to use for..next instead of do..loop
-case
marker -case
hex ram
\ of compare
(of) ( n1 n2 -- n1 flag )
inline over
inline -
0=
;
case ( -- #of )
0
; immediate
of ( #of -- #of orig )
postpone (of) ( copy and test case value)
postpone if ( add orig to control flow stack )
postpone drop ( discard case value if case is matching )
; immediate
default ( #of -- #of orig )
postpone true ( Force to take the default branch )
postpone if ( add orig to control flow stack )
postpone drop ( discard case value )
; immediate
Fred and Mikael, thank you both.
As an introduction, I've returned to forth in my retirement after about a twenty year gap not touching microprocessors. Started in the mid 1980s on the Rockwell 6502 RSC chip.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Gary, FlashForth was inspired by the RSC Forth chip which I as a newly graduated BSCEE could not afford back in the eighties.
Hope you enjoy FlashForth !
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does anyone have an example of a case flow control structure using FF on Scamp3 or any other implementation. A series of dup if then could do it but don't know which runs better.
Here is the build of a case flow I use. I had to modify it slightly in order to use the for ... next construct.
\ ***********
\ Case for FlashForth *
\ Filename: build-case.ff (voorheen case.txt) *
\ Date: 26.01.2014 *
\ FF Version: 5.0 *
\ Copyright: Mikael Nordman *
\ Author: Mikael Nordman edited by FZ *
\ **********
\ FlashForth is licensed acording to the GNU General Public License
\ *************
\ A case implementation posted by Jenny Brien on c.l.f.
\ Modified to use for..next instead of do..loop
-case
marker -case
hex ram
inline over
inline -
0=
;
0
; immediate
postpone (of) ( copy and test case value)
postpone if ( add orig to control flow stack )
postpone drop ( discard case value if case is matching )
default ( #of -- #of orig )
postpone true ( Force to take the default branch )
postpone if ( add orig to control flow stack )
postpone drop ( discard case value )
; immediate
endof ( orig1 -- orig2 #of )
postpone else
swap 1+
; immediate
endcase ( orig1..orign #of -- )
postpone drop ( discard case value )
for
postpone then ( resolve of branches )
next
; immediate
\ example:
\ : case-test
\ case
\ 11 of noop endof
\ default endof
\ endcase
\ ;
There is a case implementation available in the forth directory.
https://sourceforge.net/p/flashforth/code/ci/master/tree/forth/case.fs
https://sourceforge.net/p/flashforth/code/ci/master/tree/forth/case-test.fs
thank YOU @oh2aun !!!
Fred and Mikael, thank you both.
As an introduction, I've returned to forth in my retirement after about a twenty year gap not touching microprocessors. Started in the mid 1980s on the Rockwell 6502 RSC chip.
Gary, FlashForth was inspired by the RSC Forth chip which I as a newly graduated BSCEE could not afford back in the eighties.
Hope you enjoy FlashForth !