Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #39232 > unrolled thread

unexpected +LOOP behavior

Started bychitselb <chitselb@gmail.com>
First post2015-05-23 19:27 -0700
Last post2015-05-24 14:06 +0000
Articles 11 on this page of 151 — 19 participants

Back to article view | Back to comp.lang.forth


Contents

  unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-23 19:27 -0700
    Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-23 20:27 -0700
      Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-24 13:44 +0200
        Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-24 10:36 -0400
          Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-24 23:16 +0200
            Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-24 15:57 -0700
            Re: unexpected +LOOP behavior Bernd Paysan <bernd.paysan@gmx.de> - 2015-05-25 02:21 +0200
              Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-24 15:21 -1000
                Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-24 19:49 -0700
              Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-24 18:22 -0700
              Re: unexpected +LOOP behavior "WJ" <w_a_x_man@yahoo.com> - 2015-05-26 17:20 +0000
                Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-26 14:15 -0400
                  Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-26 08:37 -1000
                    Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-26 15:09 -0400
                      Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-26 09:19 -1000
                        Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-26 17:08 -0400
                          Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-26 15:42 -0700
                            Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-26 19:30 -0400
                              Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-26 17:45 -0700
                                Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-26 21:33 -0400
                                Re: unexpected +LOOP behavior Coos Haak <chforth@hccnet.nl> - 2015-05-27 14:08 +0200
                                  Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-27 06:32 -0700
                                    Re: unexpected +LOOP behavior Coos Haak <chforth@hccnet.nl> - 2015-05-27 16:15 +0200
                            Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-26 14:32 -1000
                          Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-27 08:30 +0000
                            Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-27 17:15 -0400
                    Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-29 21:05 -0700
            Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-25 01:41 -0400
              Re: unexpected +LOOP behavior Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-05-24 23:26 -0700
                Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-25 14:33 +0000
                Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-25 10:56 -0400
                  Re: unexpected +LOOP behavior Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-05-25 11:28 -0700
                    Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-25 14:33 -0400
                    Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-25 12:57 -0700
                    Re: unexpected +LOOP behavior humptydumpty <ouatubi@gmail.com> - 2015-05-25 23:01 -0700
            Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-25 14:21 +0000
            Re: unexpected +LOOP behavior albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-05-26 23:59 +0000
            Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-27 09:15 +0000
              Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-27 10:06 +0000
              Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-27 12:03 -0400
                Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-27 16:23 +0000
                  Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-27 12:39 -0400
              Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-27 22:14 +0200
                Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-27 17:13 -0400
                  Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-27 23:36 +0200
                    Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-27 18:06 -0400
                      Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-29 10:35 +0200
                        Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-29 12:16 +0100
                          Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-29 09:42 -0400
                          Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-29 16:16 +0200
                            Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-29 15:24 +0100
                Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-27 17:32 -0400
                  Re: unexpected +LOOP behavior Coos Haak <chforth@hccnet.nl> - 2015-05-27 23:59 +0200
                    Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-27 19:31 -0400
                  Re: unexpected +LOOP behavior Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-05-27 23:11 -0700
                Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-28 12:21 +0100
                  Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-28 12:24 +0100
                  Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-29 10:53 +0200
                    Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-29 12:19 +0100
                Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-29 13:51 +0000
                  Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-29 17:48 +0200
              Re: unexpected +LOOP behavior Bernd Paysan <bernd.paysan@gmx.de> - 2015-05-29 02:08 +0200
                Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-29 08:25 +0000
                  Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-29 12:40 +0100
                    Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-29 13:16 +0000
                    Re: unexpected +LOOP behavior albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-05-29 18:43 +0000
                      Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-29 20:08 +0100
                      x86 tricks Lars Brinkhoff <lars.spam@nocrew.org> - 2015-06-05 09:42 +0200
                        Re: x86 tricks albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-06-05 09:32 +0000
                        Re: x86 tricks anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-06-05 09:40 +0000
                          Re: x86 tricks albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-06-05 11:17 +0000
                            Re: x86 tricks anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-06-05 15:49 +0000
                              Re: x86 tricks "Alex McDonald" <blog@rivadpm.com> - 2015-06-05 17:45 +0100
                                Re: x86 tricks anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-06-05 16:53 +0000
                                  Re: x86 tricks rickman <gnuarm@gmail.com> - 2015-06-07 13:20 -0400
                                    Re: x86 tricks anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-06-08 07:18 +0000
                                  Re: x86 tricks Bernd Paysan <bernd.paysan@gmx.de> - 2015-06-08 17:18 +0200
                                    Re: x86 tricks Tessa Bonting <tessa.bonting@gmail.com> - 2015-06-08 08:42 -0700
                              Re: x86 tricks albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-06-06 09:47 +0000
                                Re: x86 tricks anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-06-07 15:05 +0000
                                  Re: x86 tricks "Alex McDonald" <blog@rivadpm.com> - 2015-06-07 17:49 +0100
                        Re: x86 tricks "Alex McDonald" <blog@rivadpm.com> - 2015-06-05 13:19 +0100
        Re: unexpected +LOOP behavior Mark Wills <markwills1970@gmail.com> - 2015-05-25 01:38 -0700
    Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-23 21:33 -0700
      Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-23 22:10 -0700
        Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-23 22:20 -0700
          Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-25 21:13 -0700
            Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-27 17:34 -0400
              Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-27 22:04 -0700
                Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-28 01:27 -0400
                  Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-28 03:20 -0400
                    Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-28 04:13 -0400
                      Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-29 04:23 -0400
                        Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-29 11:28 -0400
                          Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-29 18:32 -0400
                            Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-29 18:53 -0400
        Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-23 22:26 -0700
          Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-23 21:37 -1000
            Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-24 10:24 -0700
              Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-24 20:40 -0400
              Re: unexpected +LOOP behavior Hans Bezemer <the.beez.speaks@gmail.com> - 2015-05-25 14:08 +0200
                Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-25 17:27 -0400
                  Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-25 14:47 -1000
                    Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-27 17:33 -0400
              Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-25 12:53 -0700
                Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-25 13:05 -0700
                Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-25 14:49 -1000
                  Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-25 18:03 -0700
                    Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-05-25 16:44 -1000
                    Re: unexpected +LOOP behavior humptydumpty <ouatubi@gmail.com> - 2015-05-25 22:56 -0700
                    Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-26 08:05 +0000
          Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-24 10:43 -0400
            Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-24 08:29 -0700
              Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-24 15:44 +0000
                Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-27 00:57 -0700
                Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-06-05 13:11 -0700
                  Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-06-05 12:24 -1000
                    Re: unexpected +LOOP behavior JennyB <jennybrien@googlemail.com> - 2015-06-06 13:29 -0700
                    Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-06-07 14:56 +0000
                      Re: unexpected +LOOP behavior "Elizabeth D. Rather" <erather@forth.com> - 2015-06-07 10:38 -1000
                        Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-06-08 08:08 +0000
          Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-24 10:01 -0700
        Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-24 10:40 -0400
          Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-24 11:29 -0700
            Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-25 09:51 -0700
              Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-25 10:44 -0700
                Re: unexpected +LOOP behavior "Alex McDonald" <blog@rivadpm.com> - 2015-05-25 12:34 -0700
                  Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-25 12:59 -0700
    unexpected +LOOP behavior Mark Wills <markwills1970@gmail.com> - 2015-05-24 01:39 -0700
      Re: unexpected +LOOP behavior Coos Haak <chforth@hccnet.nl> - 2015-05-24 14:46 +0200
        Re: unexpected +LOOP behavior Mark Wills <markwills1970@gmail.com> - 2015-05-25 01:17 -0700
      Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-24 20:48 -0400
        Re: unexpected +LOOP behavior hughaguilar96@gmail.com - 2015-05-24 18:15 -0700
        Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-25 12:35 +0000
          Re: unexpected +LOOP behavior "Rod Pemberton" <fork@lllljunkqwer.cpm> - 2015-05-25 17:27 -0400
            Re: unexpected +LOOP behavior rickman <gnuarm@gmail.com> - 2015-05-25 18:16 -0400
              Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-25 16:17 -0700
                Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-25 17:16 -0700
                  Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-25 17:50 -0700
                    Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-25 18:47 -0700
                Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-25 20:01 -0700
                  Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-25 20:29 -0700
                  Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-25 20:32 -0700
                Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-26 08:03 +0000
                  Re: unexpected +LOOP behavior Mark Wills <markwills1970@gmail.com> - 2015-05-26 01:10 -0700
                    Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-26 22:31 -0700
                  Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-26 20:07 -0700
                  Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-26 20:20 -0700
                    Re: unexpected +LOOP behavior Michael Barry <barrym95838@yahoo.com> - 2015-05-26 22:00 -0700
                      Re: unexpected +LOOP behavior chitselb <chitselb@gmail.com> - 2015-05-27 02:41 -0700
    Re: unexpected +LOOP behavior anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-05-24 14:06 +0000

Page 8 of 8 — ← Prev page 1 2 3 4 5 6 7 [8]


#39317

FromMichael Barry <barrym95838@yahoo.com>
Date2015-05-25 20:01 -0700
Message-ID<98271dfe-cab0-4625-8aa0-885ca130e87f@googlegroups.com>
In reply to#39308
On Monday, May 25, 2015 at 4:17:35 PM UTC-7, chitselb wrote:
> Here is what I came up with.  Tested. http://github.com/chitselb/pettil
> [snip]
>     and #$80
>     beq branch
> [snip]

Is there something in branch preventing you from just doing a
      bpl branch
   here instead?

Mike

[toc] | [prev] | [next] | [standalone]


#39318

Fromchitselb <chitselb@gmail.com>
Date2015-05-25 20:29 -0700
Message-ID<4ef5070d-fab6-4e2a-ae6d-a6d5d9810ed9@googlegroups.com>
In reply to#39317
It tests the xor of the sign bits of 'step' and 'limit-index+1' (+1 comes from the clc prior to subtracting). CARRY and oVerflow flags are ignored.

[toc] | [prev] | [next] | [standalone]


#39319

Fromchitselb <chitselb@gmail.com>
Date2015-05-25 20:32 -0700
Message-ID<77ef969e-d08b-4a52-ac3f-9fe0570bd91e@googlegroups.com>
In reply to#39317
Your bpl branch is shorter/faster/better 

[toc] | [prev] | [next] | [standalone]


#39325

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-05-26 08:03 +0000
Message-ID<2015May26.100322@mips.complang.tuwien.ac.at>
In reply to#39308
chitselb <chitselb@gmail.com> writes:
>Here is what I came up with.  Tested. http://github.com/chitselb/pettil
>
>name=(LOOP)
>ploop
>    lda #1
>    ldy #0
>    jsr push6502
>    ; fall through
>
>name=(+LOOP)
>pploop
>    clc
>    lda tos
>    sta n
>    adc zi
>    sta zi
>    lda tos+1
>    adc zi+1
>    sta zi+1
>    jsr slide
>
>    clc
>    lda zlim
>    sbc zi
>    lda zlim+1
>    sbc zi+1
>    eor n
>    and #$80
>    beq branch
>ploop02
>    pla                 ; unnest outer loop from return stack
>    sta zi
>    pla
>    sta zi+1
>    pla
>    sta zlim
>    pla
>    sta zlim+1
>    jmp bump            ; skip branch offset byte, NEXT

I see no bvs or bvc here.  Have you looked at the V-flag-using technique?

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2015: http://www.mpeforth.com/euroforth2015/euroforth2015.htm

[toc] | [prev] | [next] | [standalone]


#39326

FromMark Wills <markwills1970@gmail.com>
Date2015-05-26 01:10 -0700
Message-ID<c876ede9-e764-430a-87ae-80d3ba71f9d0@googlegroups.com>
In reply to#39325
On Tuesday, 26 May 2015 09:05:06 UTC+1, Anton Ertl  wrote:
> chitselb <chitselb@gmail.com> writes:
> >Here is what I came up with.  Tested. http://github.com/chitselb/pettil
> >
> >name=(LOOP)
> >ploop
> >    lda #1
> >    ldy #0
> >    jsr push6502
> >    ; fall through
> >
> >name=(+LOOP)
> >pploop
> >    clc
> >    lda tos
> >    sta n
> >    adc zi
> >    sta zi
> >    lda tos+1
> >    adc zi+1
> >    sta zi+1
> >    jsr slide
> >
> >    clc
> >    lda zlim
> >    sbc zi
> >    lda zlim+1
> >    sbc zi+1
> >    eor n
> >    and #$80
> >    beq branch
> >ploop02
> >    pla                 ; unnest outer loop from return stack
> >    sta zi
> >    pla
> >    sta zi+1
> >    pla
> >    sta zlim
> >    pla
> >    sta zlim+1
> >    jmp bump            ; skip branch offset byte, NEXT
> 
> I see no bvs or bvc here.  Have you looked at the V-flag-using technique?
> 
> - anton
> -- 
> M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
> comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
>      New standard: http://www.forth200x.org/forth200x.html
>    EuroForth 2015: http://www.mpeforth.com/euroforth2015/euroforth2015.htm

My implementation (which uses the overflow detection technique) is here:

http://turboforth.net/source/Bank0/0-05-FlowControl.html

Scroll down and look for the code for DO (DO) LOOP and (LOOP)

It's heavily commented.

It's actually very easy to do. There is a little bit of magic in I and J
to account for the index offset. That's it.

[toc] | [prev] | [next] | [standalone]


#39349

FromMichael Barry <barrym95838@yahoo.com>
Date2015-05-26 22:31 -0700
Message-ID<bc6e3baf-f441-4412-b018-26786012c061@googlegroups.com>
In reply to#39326
On Tuesday, May 26, 2015 at 1:10:33 AM UTC-7, Mark Wills wrote:
> ...
> My implementation (which uses the overflow detection technique) is here:
> 
> http://turboforth.net/source/Bank0/0-05-FlowControl.html
> 
> Scroll down and look for the code for DO (DO) LOOP and (LOOP)
> 
> It's heavily commented.
> 
> It's actually very easy to do. There is a little bit of magic in I and J
> to account for the index offset. That's it.

That old TI (99xx??) has a pretty tidy assembly language.  Too bad I
  don't have any more spare time to play with it right now.

Mike

[toc] | [prev] | [next] | [standalone]


#39346

FromMichael Barry <barrym95838@yahoo.com>
Date2015-05-26 20:07 -0700
Message-ID<4f8bb578-b650-48e2-8d5c-dfcfb35b71d3@googlegroups.com>
In reply to#39325
On Tuesday, May 26, 2015 at 1:05:06 AM UTC-7, Anton Ertl wrote:
> ...
> I see no bvs or bvc here.  Have you looked at the V-flag-using technique?
> 
> - anton
> 

I tried your idea above to fudge in (+LOOP) and use V, but it is
  much more expensive than chitselb's version, at least with my
  current level of skill coding in 6502 assembly.  Maybe if he went
  with a fudged (DO) and modified I and J, it might have a chance
  to compete with his current version, but I doubt it.  There's
  just too much "busy work" dealing with cells that are twice the
  width of your machine registers, and I think he hit the most
  economical strategy under the circumstances.  I'm not the best
  6502 coder I know (not even close), so I may be wrong, but the
  odds are against it.

Mike

[toc] | [prev] | [next] | [standalone]


#39347

Fromchitselb <chitselb@gmail.com>
Date2015-05-26 20:20 -0700
Message-ID<49eee7cd-37d8-4c4e-b18c-44178276d1ec@googlegroups.com>
In reply to#39325
On Tuesday, May 26, 2015 at 4:05:06 AM UTC-4, Anton Ertl wrote:
> chitselb  writes:
> >Here is what I came up with.  Tested. http://github.com/chitselb/pettil
> > [ old code snipped ]
> 
> I see no bvs or bvc here.  Have you looked at the V-flag-using technique?
> 
> - anton
> -- 
> M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
> comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
>      New standard: http://www.forth200x.org/forth200x.html
>    EuroForth 2015: http://www.mpeforth.com/euroforth2015/euroforth2015.htm

Thanks for the gentle nudge in the direction of better.  This code works properly and covers the full 64K range.  It does seem big/slow to me, so I'll probably play around and try to code golf it down some more.

It should be noted that PETTIL does some things differently, like `tos` is separate from the rest of the data stack, and is maintained by push/pop routines.  Also the innermost do-loop index and limit are stored in zero page, not the return stack as is conventionally done on 6502.  Here's tested code:

name=(LOOP)
ploop
    inc zi
    bne ploop01
    inc zi+1
ploop01
    lda zi
    eor zlim
    bne branch
    lda zi+1
    eor zlim+1
    bne branch
    beq ploop02


name=(+LOOP)
pploop
    sec
    lda zi
    sbc zlim
    sta n
    lda zi+1
    sbc zlim+1
    eor #$80
    sta n+1
    clc
    lda tos
    adc n
    lda tos+1
    adc n+1
    php
    clc
    lda tos
    adc zi
    sta zi
    lda tos+1
    adc zi+1
    sta zi+1
    jsr slide           ; DROP as a native subroutine
    plp
    bvc branch

ploop02
    pla                 ; unnest outer loop from return stack
    sta zi
    pla
    sta zi+1
    pla
    sta zlim
    pla
    sta zlim+1
    jmp bump             ; skip the branch offset byte and JMP NEXT,
                         ; with page crossing

[toc] | [prev] | [next] | [standalone]


#39348

FromMichael Barry <barrym95838@yahoo.com>
Date2015-05-26 22:00 -0700
Message-ID<a5a65217-18c8-411b-b79a-1ef48aa8273f@googlegroups.com>
In reply to#39347
On Tuesday, May 26, 2015 at 8:20:06 PM UTC-7, chitselb wrote:
> ...
> pploop
>     sec
>     lda zi
>     sbc zlim
>     sta n
>     lda zi+1
>     sbc zlim+1
>     eor #$80
>     sta n+1
>     clc
>     lda tos
>     adc n
>     lda tos+1
>     adc n+1
>     php
>     clc
>     lda tos
>     adc zi
>     sta zi
>     lda tos+1
>     adc zi+1
>     sta zi+1
>     jsr slide           ; DROP as a native subroutine
>     plp
>     bvc branch
> ...

That's kinda similar to what I was trying to do, but neither
  your attempt nor mine clearly beat your original pploop:

    ...
pploop
    lda zi
    pha                 ; stash I
    clc
    adc tos             ; I += TOS
    sta zi
    lda zi+1
    tay
    adc tos+1
    sta zi+1
    pla
    sec
    sbc zlim            ; calculate:
    pha                 ;   stashed I - limit + $8000
    tya
    sbc zlim+1
    eor #$80
    tay
    pla
    clc
    adc TOS             ; if result + TOS sets V
    tya                 ; then loop is complete
    adc TOS+1
    jsr slide           ; drop TOS
    bvc branch
    ...

My coding attempt has a slightly smaller footprint than yours,
  but is untested, and assumes that slide doesn't mess with V.

Mike

[toc] | [prev] | [next] | [standalone]


#39353

Fromchitselb <chitselb@gmail.com>
Date2015-05-27 02:41 -0700
Message-ID<96bd7dbb-e7cc-4f7a-a526-8c5035050d65@googlegroups.com>
In reply to#39348
On Wednesday, May 27, 2015 at 1:00:06 AM UTC-4, Michael Barry wrote:
> On Tuesday, May 26, 2015 at 8:20:06 PM UTC-7, chitselb wrote:
> > ...
> > pploop
> >     sec
> >     lda zi
> >     sbc zlim
> >     sta n
> >     lda zi+1
> >     sbc zlim+1
> >     eor #$80
> >     sta n+1
> >     clc
> >     lda tos
> >     adc n
> >     lda tos+1
> >     adc n+1
> >     php
> >     clc
> >     lda tos
> >     adc zi
> >     sta zi
> >     lda tos+1
> >     adc zi+1
> >     sta zi+1
> >     jsr slide           ; DROP as a native subroutine
> >     plp
> >     bvc branch
> > ...
> 
> That's kinda similar to what I was trying to do, but neither
>   your attempt nor mine clearly beat your original pploop:
> 
>     ...
> pploop
>     lda zi
>     pha                 ; stash I
>     clc
>     adc tos             ; I += TOS
>     sta zi
>     lda zi+1
>     tay
>     adc tos+1
>     sta zi+1
>     pla
>     sec
>     sbc zlim            ; calculate:
>     pha                 ;   stashed I - limit + $8000
>     tya
>     sbc zlim+1
>     eor #$80
>     tay
>     pla
>     clc
>     adc TOS             ; if result + TOS sets V
>     tya                 ; then loop is complete
>     adc TOS+1
>     jsr slide           ; drop TOS
>     bvc branch
>     ...
> 
> My coding attempt has a slightly smaller footprint than yours,
>   but is untested, and assumes that slide doesn't mess with V.
> 
> Mike

slip/slide change: A, X, N, Z
slip/slide don't change: Y, C, V

slide
    lda stackh,x                ; slide something off of the stack
    sta tos+1
    lda stackl,x
    sta tos
    inx
    rts

slip
    dex                         ; slip something onto the stack
    lda tos+1
    sta stackh,x
    lda tos
    sta stackl,x
    rts

[toc] | [prev] | [next] | [standalone]


#39246

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-05-24 14:06 +0000
Message-ID<2015May24.160612@mips.complang.tuwien.ac.at>
In reply to#39232
chitselb <chitselb@gmail.com> writes:
>I'm reimplementing +LOOP in my homebrew Forth, and want to mostly do the right thing with standard words.  This is what gforth does:
...
>: foo 0 20 do i . -4 +loop ; 
>foo 20 16 12 8 4 0  ok
>: foo 20 0 do i . 4 +loop ; 
>foo 0 4 8 12 16  ok
>
>These results threw me off.  Why does the standard have that extra iteration for negative loop increments?

As others remarked, that appears to have been done to enable an
efficient implementation (at the cost of a less intuitive programming
interface).

The Gforth manual says:

|    * The behaviour of n +LOOP is peculiar when n is negative:
|
|                -1 0 ?DO  i .  -1 +LOOP
|           
|
|      prints 0 -1
|
|                0 0 ?DO  i .  -1 +LOOP
|           
|
|      prints nothing.
|
|      Therefore we recommend avoiding n +LOOP with negative n. One
|      alternative is u -LOOP, which reduces the index by u each
|      iteration. The loop is terminated when the border between
|      limit+1 and limit is crossed. Gforth also provides -DO and U-DO
|      for down-counting loops. E.g.:
|
|                -2 0 -DO  i .  1 -LOOP
|           
|
|      prints 0 -1
|
|                -1 0 -DO  i .  1 -LOOP
|           
|
|      prints 0
|
|                0 0 -DO  i .  1 -LOOP
|           
|
|      prints nothing. 
|
|Unfortunately, +DO, U+DO, -DO, U-DO and -LOOP are not defined in ANS
|Forth. However, an implementation for these words that uses only
|standard words is provided in compat/loops.fs.

However, I have also found that, for, say, loop boundaries addr and
addr+20, with stride -4, I usually want the sequence of I to be

addr+16 addr+12 addr+8 addr+4 addr+0

I don't think anyone has introduced a counted loop yet that allows to
express that conveniently.  OTOH, one does not need that that often.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2015: http://www.mpeforth.com/euroforth2015/euroforth2015.htm

[toc] | [prev] | [standalone]


Page 8 of 8 — ← Prev page 1 2 3 4 5 6 7 [8]

Back to top | Article view | comp.lang.forth


csiph-web