[PicForth] Optimiser problem
David McNab
david at rebirthing.co.nz
Thu Nov 18 06:54:52 CET 2004
Hi,
I'm trying to write PicForth code which generates subwf instructions,
and not having much luck.
Sample code:
variable v1
: fred
1 v1 -!
;
With optimisation on, this (correctly) generates:
decf v1,f
return
I then tried:
variable v1
: fred
disallow-optimizations
1 v1 -!
allow-optimizations
;
I hoped this would generate something like:
movlw 1
subwf v1,f
However, it generates the same as above.
My situation is that I need to decrement 16-bit and 24-bit values to
zero, which requires generation of code that impacts the Carry bit. But
I can't work out how to do this in pure PicForth
So what I'm having to do is:
variable vL
variable vM
variable vH
: v-- ( -- ) \ decrememnts 24-bit value vH:vM:vL
\ decrement vL
]asm
1 movlw
vL adjust-bank ,f subwf
asm[
c bit-clr? if
\ got a borrow, decrement vM
]asm
vM ,f subwf \ W still = 1
asm[
c bit-clr? if
\ got a borrow, decrement vH
1 vH -! \ don't need C, no need for asm code
then
then
restore-bank
;
Any thoughts/ideas on all this?
--
Cheers
David
More information about the PicForth
mailing list