Hello
After a long debugging session i found the two following bugs (wich are probably connected).
When I assign a value from an array of structs to another variable and do some math on the same line, I get ot wrong values.
wrong value
uart_tx_buffer_LEN => 216
:::asm
; .line 87; src/modules/app_ep1_out.c uart_tx_buffer_LEN = ep_bdt[2].Cnt-1;
MOVFF (_ep_bdt + 9), (_ep_bdt + 9)
DECF (_ep_bdt + 9), W, B
BANKSEL _uart_tx_buffer_LEN
MOVWF _uart_tx_buffer_LEN, B
oke value
uart_tx_buffer_LEN => 8
:::asm
; .line 87; src/modules/app_ep1_out.c uart_tx_buffer_LEN = ep_bdt[2].Cnt;
MOVFF (_ep_bdt + 9), _uart_tx_buffer_LEN
BANKSEL _uart_tx_buffer_LEN
; .line 88; src/modules/app_ep1_out.c uart_tx_buffer_LEN--;
DECF _uart_tx_buffer_LEN, F, B
uart_tx_start_condition_index isn't incremented here
:::asm
; .line 329; my.c TXREG = uart_start_condition[uart_tx_start_condition_index++];
MOVFF _uart_tx_start_condition_index, r0x00
INCF _uart_tx_start_condition_index, F, B
CLRF r0x01
CLRF r0x02
MOVLW LOW(_uart_start_condition)
ADDWF r0x00, F
MOVLW HIGH(_uart_start_condition)
ADDWFC r0x01, F
MOVLW UPPER(_uart_start_condition)
ADDWFC r0x02, F
MOVFF r0x00, TBLPTRL
MOVFF r0x01, TBLPTRH
MOVFF r0x02, TBLPTRU
TBLRD*+
MOVFF TABLAT, _TXREG
this works as expected
:::asm
; .line 329; my.c TXREG = uart_start_condition[uart_tx_start_condition_index];
MOVLW LOW(_uart_start_condition)
; removed redundant BANKSEL
ADDWF _uart_tx_start_condition_index, W, B
MOVWF r0x00
CLRF r0x01
MOVLW HIGH(_uart_start_condition)
ADDWFC r0x01, F
CLRF r0x02
MOVLW UPPER(_uart_start_condition)
ADDWFC r0x02, F
MOVFF r0x00, TBLPTRL
MOVFF r0x01, TBLPTRH
MOVFF r0x02, TBLPTRU
TBLRD*+
MOVFF TABLAT, _TXREG
; removed redundant BANKSEL
; .line 330; my.c uart_tx_start_condition_index++;
INCF _uart_tx_start_condition_index, F, B
I'm using the most recent svn sdcc-version configured with :
:::bash
./configure \
--disable-doc \
--disable-mcs51-port \
--disable-z80-port \
--disable-z180-port \
--disable-r2k-port \
--disable-r3ka-port \
--disable-gbz80-port \
--disable-ds390-port \
--disable-ds400-port \
--disable-hc08-port \
--disable-s08-port \
--disable-ucsim \
--enable-libgc \
--enable-new-pics
and the most recent svn gputils.
The files are compiled with the following command line :
:::make
sdcc -o $(my.o) -mpic16 -p18f2550 --use-non-free --std-sdcc99 --obanksel=9 --opt-code-size --optimize-cmp --optimize-df --denable-peeps $(my.include.paths) -c $(my.c)
Cheers,
Oli