Re: [Flashforth-devel] For-next loops - the New Design
Brought to you by:
oh2aun
From: om1zz <om...@vo...> - 2015-05-28 13:12:01
|
Peter, long time back (2009-10??) there was no do-loop implemented, and we had discusions about that, afaik. The reason was it was difficult to implement, heavy and therefore slow. Instead of that, Mike did FOR, which is very fast, as it does just a single instruction check when passing index to zero. That introduces the bug (my interpretation) which has not been discovered till today (why?). Mike has written the do-loop recently (as the external .txt source) for compatibility reasons (as I claimed long time back mainly because my intention with floating point library which uses do-loop, and others). Forth is a "better assembler" or "clever assembler" used today for low level programming on hardware. No high-level elements there. Just a simple puzzle. When working so close to the HW you must admit the hw-specific behaviour of the forth. So - shooting a zero into a loop means it will underrun (within the size of the basic cell, here 16bit) and loop over till zero (65536x). That is normal, and this is how the MCU works (all of them, PIC, AVR, ARM, MIPS, x86, etc). Pushing any "high-level intelligence" into the forth's primitive, basic, fundamental words changes the forth into a Frankenstein.. :) Igor, assistant to Mr. F. ______________________________________________________________ > Od: "om1zz" <om...@vo...> > Komu: Peter Jacobs <pe...@me...>, <fla...@li...> > Datum: 28.05.2015 14:11 > Předmět: Re: [Flashforth-devel] For-next loops - the New Design > >Peter, > >for people coming from high-level languages there will be ?for-next. > >0 for-next may loop 65536 times, because the do-loop does the same (and it is therefore consistent), >You may try (in FF btw.): > >: mytest do i u. loop ; >0 0 mytest > >what you will see? This: > >0 0 mytest 0 1 2 3 4 5 6 7 8... >65533 65534 65535 ok<#,ram> > >It loops 65536 times (2^16). That is normal in forth. > >Forth is not a high-level language, that has to be explained to the people coming from high-level area.. > >Igor > >______________________________________________________________ >> Od: Peter Jacobs <pe...@me...> >> Komu: <fla...@li...> >> Datum: 28.05.2015 13:27 >> Předmět: Re: [Flashforth-devel] For-next loops - the New Design >> >>Igor, >> I'm going to disagree with you on preference. I think that most >>people will come to FF, not from assembler, but from some other >>high-level language and they will expect "0 for" to iterate 0 times. I >>know that I do. If I wanted to iterate 65536 times in one of my >>programs, I'd likely be wanting to do more iterations at some point and >>I'd use a 24-bit or 32-bit counter anyway. >>Regards, >>Peter J. >> >> >>On 28/05/15 21:03, om1zz wrote: >>> Do you insist on a single asm instruction for the entire for-next loop implementation? >>> Do-loop is min 30 instructions in FF. >>> >>> I think that with N vs. N+1 idea when handling for (in any form) you break the consistency of for-loop implementation understanding. >>> >>> I would easily spend another 1-2 asm instructions and do it consistent. Speed plays no role here. >>> When somebody wants to bitbang a pin it could be done in asm. >>> >>> N for .. >>> N ?for .. >>> >>> both will do N loops through the body. The only diff is the ?for skips zero. That is very consistent. >>> >>> 0 for >>> >>> will do M loops where M=2^16 in this case. That is also consistent as you work with 16bit assembler. >>> >>> I am suggesting that as a standard for the for-loop design for any architecture on my github. >>> >>> Igor. >>> >>> >>> >>> >>> ______________________________________________________________ >>>> Od: Mikael Nordman <mik...@fl...> >>>> Komu: <fla...@li...> >>>> Datum: 27.05.2015 17:59 >>>> Předmět: Re: [Flashforth-devel] For-next loops - the New Design >>>> >>>> Yes, Yes, >>>> I understand what you want. >>>> But you dont seem to understand that it cannot be done >>>> in a simple for..next loop that has only one decrement and branch >>>> instruction, and that has an index that counts down to zero. >>>> >>>> In order the get the full 16 bit loop count you have to give as input >>>> the N+1 count. >>>> >>>> But if you have some idea how to implement it in PIC assembly code, >>>> please write it out. >>>> >>>> BR Mike >>>> >>>> On 27.05.2015 10:32, om1zz wrote: >>>>> 0 _for 65535 65534 .. >>>>> .. 13 12 11 10 9 8 7 6 5 4 3 2 1 0 >>>>> 65536 ok<#,ram> >>>> ------------------------------------------------------------------------------ >>>> _______________________________________________ >>>> Flashforth-devel mailing list >>>> Fla...@li... >>>> https://lists.sourceforge.net/lists/listinfo/flashforth-devel >>>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> Flashforth-devel mailing list >>> Fla...@li... >>> https://lists.sourceforge.net/lists/listinfo/flashforth-devel >> >> >>------------------------------------------------------------------------------ >>_______________________________________________ >>Flashforth-devel mailing list >>Fla...@li... >>https://lists.sourceforge.net/lists/listinfo/flashforth-devel >> > |