For the C source
int CmdBytes;
...
CmdBytes = CmdBytes - 1;
This is generated
2950 ; main.c:490: CmdBytes = CmdBytes - 1;
2951 ; genMinus
2952 ; genMinusDec
0007E4 EB [12] 2953 mov a,r3
0007E5 24 FF [12] 2954 add a,#0xff
0007E7 FA [12] 2955 mov r2,a
0007E8 EA [12] 2956 mov a,r2
0007E9 34 FF [12] 2957 addc a,#0xff
0007EB FB [12] 2958 mov r3,a
As a result when CmdBytes is 0x0005 the result of the decrement is 0x0404.
SDCC versions 4.2.0, 4.3.0 and 4.4.0-rc3 all show the same bug.
I have been trying to simplify the code, but the bug is dependent on the registers assigned CmdBytes. Some minor edits cause CmdBytes to be assigned to a different set of registers for which correct code is generated. Other edits cause the source and destination register sets to be different and again correct code is generated.
All SDCC versions were built from sources on Ubuntu 20.04.1.
The command line to build main.c was:
skip@Dell-7040:~/esl/dmitrygr-einkTags/firmware/proxy$ ./build_main.sh
++ '[' '!' -e build ']'
++ mkdir build
++ sdcc -c main.c -I../board/chroma29r -I../soc/cc111x -I../8051 -I../../common -I../common -I../cpu/8051 -I. --code-size 0x7f80 --xram-loc 0xf000 --xram-size 0xda2 --model-medium -mmcs51 --std-c2x --opt-code-size --fomit-frame-pointer -DNO_AUTO_UART_SWITCH -DBUILD_TYPE=chroma29r -MD -DPROXY_BUILD -I. --debug --fverbose-asm --no-peep -o build/main.rel
main.c:153: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
Please find attached main.c, main.lst plus the complete project source.
The script build_main.sh compiles just main.c.
I've also inluded the scripts that I used to compile SDCC in the sdcc directory.
The project is open source and is here if anyone is interested: https://github.com/skiphansen/dmitrygr-einkTags
reduced code:
command line: sdcc --model-medium -mmcs51 --no-peep -c test.c
Just an observation:
When compiling with
--i-code-in-asmthe i-code reveals that the order of r3 r4 is different for iTemp2 and iTemp13. This looks odd to me. Any idea why that is different?