In sdcc/src/pic14/peeph.def:
replace restart {
comf %1,w
movwf %1
} by {
; peep 12 - Removed redundant move
comf %1,f
}
Original code also sets W to the result of comf. Replacement doesn't.
Code to reproduce:
#include <pic16f887.h>
#include <stdint.h>
void main(void)
{
uint8_t j = 0;
while (1)
{
j = ~j;
RD6 = j & 1;
}
}
For buggy result:
sdcc -mpic14 -p16f887 --use-non-free test.c
For bug-free result:
sdcc -mpic14 -p16f887 --no-peep --use-non-free test.c
Also changing j to volatile works around the issue.
sdcc -v:
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.5.4 #9304 (MINGW32)
Fixed in revision #9307.
Philipp