When the attached file is compiled with:
sdcc --use-non-free -mpic14 -p16f887 -c test.c
the code line
u8Digit = (uint8_t)((uint16_t)n16 % (uint16_t)10);
behaves as if n16 is always 0.
In the produced assembly, the MOVFs that should be copying the n16 operand to the stack are commented out. The result is that W and STK00 both contain 0x00.
_00108_DS_ ; .line 33; "test.c" u8Digit = (uint8_t)((uint16_t)n16 % (uint16_t)10); MOVLW 0x0a MOVWF STK02 MOVLW 0x00 MOVWF STK01 ;;102 MOVF r0x100D,W ;;107 MOVF r0x1008,W MOVWF STK00 ;;104 MOVF r0x100E,W ;;109 MOVF r0x1007,W PAGESEL __moduint CALL __moduint
When compiling with
sdcc --no-pcode-opt --use-non-free -mpic14 -p16f887 -c test.c
the result is as intended.
sdcc -v:
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.5.4 #9317 (Linux)