Hello everyone!

I am certain that there is an issue with _moduchar at pic14 lib. I attached the generated assembly instructions of my function. The fault arises after _moduchar is called. The value of pos (after pos %= UART_REC_BUF_LEN;) is wrong, as it turns out to be zero in cases where it should contain a different value. That means:

pos = 2;
pos %= 5;

results in: pos = 0

I intentionally loaded the values from the struct uart_rec_buffer into local variables for debugging reasons. Don't wonder...

The code calling _moduchar is executed inside my main-loop and might be interrupted by an ISR. Does this cause such problems? That is the only thing I am not sure about.

Can you tell me where to find the assembly for _moduchar (in my system)? I would like to supply you with the block of code (I can only find the c version).

I had to change all modulo operations to if/then in order to get rid of this bug. This means faster assembly code, but I think this bug should be identified (or at least communicated to other) and fixed.


Best regards,

Peter


sdcc --version
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.5.0 #9253 (Jun 20 2015) (MINGW64)

_fifo_dequeue    ;Function start
; 2 exit points
;    .line    198; "uart.c"    uint8_t pos = uart_rec_buffer.begin;
    BANKSEL    _uart_rec_buffer
    MOVF    (_uart_rec_buffer + 5),W
;    .line    199; "uart.c"    unsigned char c = uart_rec_buffer.data[pos];
    BANKSEL    r0x1014
    MOVWF    r0x1014
    ADDLW    (_uart_rec_buffer + 0)
    MOVWF    r0x1015
    MOVLW    high (_uart_rec_buffer + 0)
    BTFSC    STATUS,0
    ADDLW    0x01
    MOVWF    r0x1016
    MOVF    r0x1015,W
    BANKSEL    FSR
    MOVWF    FSR
    BCF    STATUS,7
    BANKSEL    r0x1016
    BTFSC    r0x1016,0
    BSF    STATUS,7
    BANKSEL    INDF
    MOVF    INDF,W
    BANKSEL    r0x1017
    MOVWF    r0x1017
; .line 203; "uart.c" uart_rec_buffer.data[pos] = PROTOCOL_NON_ECHO_DUMMY;
    MOVF    r0x1014,W
    ADDLW    (_uart_rec_buffer + 0)
    MOVWF    r0x1015
    MOVLW    high (_uart_rec_buffer + 0)
    BTFSC    STATUS,0
    ADDLW    0x01
    MOVWF    r0x1016
    MOVF    r0x1015,W
    BANKSEL    FSR
    MOVWF    FSR
    BCF    STATUS,7
    BANKSEL    r0x1016
    BTFSC    r0x1016,0
    BSF    STATUS,7
    MOVLW    0x00
    BANKSEL    INDF
    MOVWF    INDF
;    .line    205; "uart.c"    ++pos;
    BANKSEL    r0x1014
    INCF    r0x1014,F
;    .line    206; "uart.c"    pos %= UART_REC_BUF_LEN;
    MOVLW    0x05
    MOVWF    STK00
    MOVF    r0x1014,W
    PAGESEL    __moduchar
    CALL    __moduchar
    PAGESEL    $
;    .line    208; "uart.c"    uart_rec_buffer.begin = pos;
    BANKSEL    r0x1014
    MOVWF    r0x1014
    BANKSEL    _uart_rec_buffer
    MOVWF    (_uart_rec_buffer + 5)
;    .line    210; "uart.c"    --uart_rec_buffer.len;
    DECF    (_uart_rec_buffer + 7),W
    BANKSEL    r0x1015
    MOVWF    r0x1015
    BANKSEL    _uart_rec_buffer
    MOVWF    (_uart_rec_buffer + 7)
    .... (some debug output I cut out)
    BANKSEL    r0x1017
    MOVF    r0x1017,W
    RETURN
; exit point of _fifo_dequeue


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to