[PicForth] Festive code generation bug
Alex Holden
alex at linuxhacker.org
Sat Dec 25 15:31:37 CET 2004
Merry Christmas everybody.
I've found another code generation bug, this time involving nested if
statements with 'exit' in them. Here's an example. It should exit with
-1 on the stack if passed 1, exit with 0 on the stack if passed 2, and
leave nothing on the stack if passed anything else. In fact, the else
block is always skipped over, so it returns -1 when passed 1 and returns
the number that was passed in if it was anything other than 1.
: test
dup 1 = if
drop -1 exit
else
2 = if
0 exit
then
then
;
Here's the generated assembly:
; name: test
; max return-stack depth: 0
0x0006 0800 movf 0x00,w
0x0007 3A01 xorlw 0x01
0x0008 1D03 btfss 0x03,2
0x0009 280D goto 0x00D ; test + 0x007
0x000A 30FF movlw 0xFF
0x000B 0080 movwf 0x00
0x000C 0008 return
0x000D 2816 goto 0x016 ; test + 0x010
0x000E 0600 xorwf 0x00,w
0x000F 0A84 incf 0x04,f
0x0010 3800 iorlw 0x00
0x0011 1D03 btfss 0x03,2
0x0012 2816 goto 0x016 ; test + 0x010
0x0013 0384 decf 0x04,f
0x0014 0180 clrf 0x00
0x0015 0008 return
0x0016 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