[PicForth] Possible 'if' code generation bug - CORRECTION

Alex Holden alex at linuxhacker.org
Sat Nov 13 12:58:02 CET 2004


Alex Holden wrote:
> : sometest 0 ;
> : doaction ;
> main : sometest if else doaction then ;

Oops, slight typo there!

Here's what it should have been and the (still incorrect) output it 
generates:

: sometest 0 ;
: doaction ;
main : main if else doaction then ;

0x0000  018A    clrf    0x0A
0x0001  2807    goto    0x007   ; (init-picforth)
         ; name: sometest
         ; max return-stack depth: 0
0x0003  0384    decf    0x04,f
0x0004  0180    clrf    0x00
0x0005  0008    return
         ; name: doaction
         ; max return-stack depth: 0
0x0006  0008    return
         ; name: (init-picforth)
         ; max return-stack depth: 0
0x0007  3032    movlw   0x32
0x0008  0084    movwf   0x04
         ; name: main
         ; max return-stack depth: 0
0x0009  0800    movf    0x00,w
0x000A  0A84    incf    0x04,f
0x000B  3800    iorlw   0x00
0x000C  1D03    btfss   0x03,2
0x000D  2800    goto    0x000   ; main + 0x005
0x000E  280F    goto    0x00F   ; main + 0x006
0x000F  0008    return

For comparison, here is what is (correctly I think) generated if the 
'if' does have an action:

: sometest 0 ;
: doaction ;
: doaction2 ;
main : main if doaction2 else doaction then ;

0x0000  018A    clrf    0x0A
0x0001  2808    goto    0x008   ; (init-picforth)
         ; name: sometest
         ; max return-stack depth: 0
0x0003  0384    decf    0x04,f
0x0004  0180    clrf    0x00
0x0005  0008    return
         ; name: doaction
         ; max return-stack depth: 0
0x0006  0008    return
         ; name: doaction2
         ; max return-stack depth: 0
0x0007  0008    return
         ; name: (init-picforth)
         ; max return-stack depth: 0
0x0008  3032    movlw   0x32
0x0009  0084    movwf   0x04
         ; name: main
         ; max return-stack depth: 1
0x000A  0800    movf    0x00,w
0x000B  0A84    incf    0x04,f
0x000C  3800    iorlw   0x00
0x000D  1903    btfsc   0x03,2
0x000E  2811    goto    0x011   ; main + 0x007
0x000F  2007    call    0x007   ; doaction2
0x0010  2812    goto    0x012   ; main + 0x008
0x0011  2806    goto    0x006   ; doaction
0x0012  0008    return

-- 
------------ Alex Holden - http://www.linuxhacker.org ------------
If it doesn't work, you're not hitting it with a big enough hammer


More information about the PicForth mailing list