8 sdcc appears to compile the following file incorrectly. I have attached
9 the C source code, and the generated assembly code, with some comments
12 The basic problem is that a memory location is post-incremented, but
13 the register variable that shadows that memory location is NOT
14 increment, and this incorrect value is used in later calculations.
16 I compiled it with these options:
18 sdcc -mmcs51 --model-small --std-sdcc99 --code-loc 0xf000 -c bug.c
20 Here is the "sdcc -v" output:
22 SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.1 #5422 (Apr 3 2009) (UNIX)
28 unsigned char rx_byte
;
29 unsigned char input_cnt
;
32 #if !defined(__SDCC_sm83) && !defined(__SDCC_pdk14) && !defined(__SDCC_f8)
33 #define ig (*(__idata struct iglobals *) 0xf0)
43 // In the following statement, the post-increment is saved in
44 // memory, but not in the value stored in the r7 register
45 count
= ig
.input_cnt
++;
47 // In the following statement, the value of "input_cnt" stored in
48 // the r7 register is used, but it is wrong (never incremented).
58 ASSERT (do_command() == 2);
59 ASSERT (ig
.input_cnt
== 2);