Hello,
I found following small test program causes strange behavior.
-------------source code start-------------
#include <sdcc-lib.h>
#include <pic16f84a.h>
typedef unsigned char byte;
static volatile byte v = 0;
static void b() {
v = 2;
}
static void a(byte n) {
b();
v = n;
}
int main() {
a(1);
/* at this point, variable 'v' should be 1,
but 'v' becomes 2. */
for(;;);
}
-------------source code end-------------
I used following command to compile this:
$ /home/takahiro/workspace/pic/sdcc/bin/sdcc -V -mpic14 -p16f84a test.c
The compiler version is:
$ /home/takahiro/workspace/pic/sdcc/bin/sdcc -v
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.8.8 #5350 (Jan 31 2009) (UNIX)
The compiler wrote following assembly (complete assembly list attached) :
MOVLW 0x01
MOVWF _v
MOVLW 0x02
MOVWF _v
_00114_DS_
GOTO _00114_DS_
RETURN
So at the point just before the infinite loop, variable 'v' becomes 2 (should be 1).
assembly output
Can't reproduce this on Z80, changing category to pic14.
Philipp
Can confirm the bug still exists as of 2023.