[PicForth] Another possible code generation bug involving 'if' and
bank switching
Alex Holden
alex at linuxhacker.org
Fri Dec 3 21:16:17 CET 2004
I'm not certain if this one was present before the recent fix for a
similar bug or not. Basically I test if all the bytes in an array are
zero, and do one thing if they are and another if they are not. The
rollover from 0x7ff to 0x800 just happens to occur between the test for
zero and the 'else' block. The generated code causes the bank-select
instruction to be skipped and a crash to occur if the array is not all zero.
Here's some example code:
7f2 org
create somedata 2 allot
: dosomething ;
: dosomethingelse ;
main : test somedata @ somedata 1 + @ or
if dosomething
else dosomethingelse
then
;
And the resulting generated code. Note addresses 0x7fd to 0x7ff:
0x0000 018A clrf 0x0A
0x0001 2FF4 goto 0x7F4 ; (init-picforth)
; name: dosomething
; max return-stack depth: 0
0x07F2 0008 return
; name: dosomethingelse
; max return-stack depth: 0
0x07F3 0008 return
; name: (init-picforth)
; max return-stack depth: 0
0x07F4 3034 movlw 0x34
0x07F5 0084 movwf 0x04
; name: test
; max return-stack depth: 1
0x07F6 0822 movf 0x22,w
0x07F7 0384 decf 0x04,f
0x07F8 0080 movwf 0x00
0x07F9 0823 movf 0x23,w
0x07FA 0400 iorwf 0x00,w
0x07FB 0A84 incf 0x04,f
0x07FC 3800 iorlw 0x00
0x07FD 1903 btfsc 0x03,2
0x07FE 158A bsf 0x0A,3
0x07FF 2802 goto 0x002 ; test + 0x00C (0x802)
0x0800 158A bsf 0x0A,3
0x0801 2804 goto 0x004 ; test + 0x00E (0x804)
0x0802 27F3 call 0x7F3 ; dosomethingelse
0x0803 158A bsf 0x0A,3
0x0804 0008 return
On a related note, is there any way PicForth could automatically work
around the dreaded 'Bank switch over test' error? I seem to keep running
into it every time I change something. It's usually pointing at a string
defined with 'c"'. Manually inserting a 'dummy word' consisting of
several nops before the affected word usually seems to work around the
problem, until I change something elsewhere and the location of the bank
switch changes.
--
------------ 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