#2007 [PIC16] Bad TBLRD code generated?

closed-fixed
5
2013-05-25
2012-04-07
Diego Herranz
No

Hi!

Compiling this simple code, I get an error running on simulators when PC reachs address 0x2EA:

- On Proteus VSM I get the following error: Address for TBLRD*+ instruction (0x003FFBCC) is not a valid configuration address.
- On PIC Simulator IDE, the simulator crashes.

Some info:

SDCC command: sdcc --use-non-free -mpic16 -p18f4550 test.c
SDCC version: SDCC : mcs51/gbz80/z80/z180/r2k/ds390/pic16/pic14/TININative/ds400/hc08 3.1.4 #7538 (Apr 6 2012) (Linux). It also happens with 3.1.0.

Don't know if it's a compiler error or if I'm doing something wrong.

Thanks a lot.

Discussion

  • Diego Herranz
    Diego Herranz
    2012-04-07

     
    Attachments
  • Diego Herranz
    Diego Herranz
    2012-04-08

    After some research on the .lst file:

    - font5x7['H'-' '][0] generates a TBLRD to address 0x0000CC which is OK.

    - getColumnFont5x7('H', 0) generates an invalid address for TBLRD because there are two conditional instructions which in my humble (and inexperienced) opinion are wrong:

    [...]
    0002b0 0e05 movlw 0x5 MOVLW 0x05
    ----> 0002b2 be00 btfsc 0, 0x7, 0 BTFSC r0x00, 7 ; I don't know why this is needed
    ----> 0002b4 5ef4 subwf 0xf4, 0x1, 0 SUBWF PRODH, F
    0002b6 cff4 movff 0xff4, 0x2 MOVFF PRODH, r0x02
    0002b8 f002
    0002ba 6a03 clrf 0x3, 0 CLRF r0x03
    ----> 0002bc be02 btfsc 0x2, 0x7, 0 BTFSC r0x02, 7 ; I don't know why this is needed
    ----> 0002be 6803 setf 0x3, 0 SETF r0x03
    0002c0 0e04 movlw 0x4 MOVLW LOW(_font5x7)
    [...]

    Thanks a lot

     
  • Diego Herranz
    Diego Herranz
    2012-04-11

    Again after more research:

    The array is declared like this uint8_t font5x7[95][5]={...}
    So, if you want to access to font5x7[2][3] (for example), it does 5x2 + 3 = 13 and it's like reading font5x7[13].

    The assembler instructions that I didn't understand are there because this multiplication is signed.
    I think that it is signed because I do the following subtraction font5x7[ character - ' ' ][...] and there is a promotion to signed int before subtracting. Right?

    Doing this:

    uint8_t index = charachter - ' ';
    font5x7[index][...]

    seems to work because it's doing an unsigned multiplication.

    Anyway, even if its signed, I think that the result should be OK. Why is it wrong? I can't see the problem.

    Thank you very much.

     
  • Raphael Neider
    Raphael Neider
    2012-04-14

    • assigned_to: nobody --> tecodev
     
  • Raphael Neider
    Raphael Neider
    2012-04-14

    This is a bug in the pic16 implementation of signed 8x8->16 bit multiplication code generation: The result overwrites the operand (in r0x00) before the operand's sign is checked in the fix-up phase (BTFSC after MULLW).
    I have prepared a fix and will commit it later today.
    Thank you for the report.

     
  • Raphael Neider
    Raphael Neider
    2012-04-14

    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Raphael Neider
    Raphael Neider
    2012-04-14

    Fixed in SDCC r7587.

     
  • Diego Herranz
    Diego Herranz
    2012-04-15

    Thanks a lot.

    I've tested the last snapshot and It works charmless.

    Thanks!