[PicForth] Possible code generation bug involving 'if' and program
memory bank switching
Alex Holden
alex at linuxhacker.org
Fri Dec 3 12:08:33 CET 2004
Hi, I think I've found another code generation bug involving program
bank switching. This time it seems to cause the PIC to jump to lala land
when an 'if' in program memory bank 1 calls a word in program memory
bank 0 and then loops back to do the test again.
Here's a minimal example:
7f9 org
: sometest 1 ;
: dosomething ;
main : test begin sometest if dosomething then again ;
My program (which is much bigger but has a very similar construct in it)
goes mad when 'sometest' returns true. If I change the code to the
equivalent of 'begin sometest drop dosomething again' it works fine
(except of course it unconditionally calls dosomething every time around
the loop).
Here's the generated code:
0x0000 018A clrf 0x0A
0x0001 2FFE goto 0x7FE ; (init-picforth)
; name: sometest
; max return-stack depth: 0
0x07F9 3001 movlw 0x01
0x07FA 0384 decf 0x04,f
0x07FB 0080 movwf 0x00
0x07FC 0008 return
; name: dosomething
; max return-stack depth: 0
0x07FD 0008 return
; name: (init-picforth)
; max return-stack depth: 0
0x07FE 3032 movlw 0x32
0x07FF 0084 movwf 0x04
; name: test
; max return-stack depth: 1
0x0800 018A clrf 0x0A
0x0801 27F9 call 0x7F9 ; sometest
0x0802 0800 movf 0x00,w
0x0803 0A84 incf 0x04,f
0x0804 3800 iorlw 0x00
0x0805 158A bsf 0x0A,3
0x0806 1903 btfsc 0x03,2
0x0807 280A goto 0x00A ; test + 0x00A (0x80A)
0x0808 018A clrf 0x0A
0x0809 27FD call 0x7FD ; dosomething
0x080A 2800 goto 0x000 ; test (rs depth: 1) (0x800)
Where I think it's going wrong is the sequence at 0x808, 0x809, 0x80A
which is executed when 'dosomething' returns true. It sets PCLATH to
bank 0, calls a word in bank 0, then does a jump to an address in bank 1
without setting PCLATH to bank 1 first.
--
------------ 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