#362 for loop bug

closed
nobody
None
2
2013-05-25
2002-07-24
Anonymous
No

When this is compiled i (R2) is initialised to 8 and is
decremented instead of 0 and then incremented.
See the code and assembler below.

unsigned char CRC8_Serial(void)
{
unsigned char CRC = 0, i;
for(i = 0; i < 8; i++)
{
CRC = CRCTABLE[CRC ^ RomTemp[i]];
}
return CRC;
}

;------------------------------------------------------------
;Allocation info for local variables in
function 'CRC8_Serial'
;------------------------------------------------------------
; C:\SportsSc\sports.c 708
; -----------------------------------------
; function CRC8_Serial
; -----------------------------------------
_CRC8_Serial:
; C:\SportsSc\sports.c 710
mov r2,#0x00
; C:\SportsSc\sports.c 715
mov r3,#0x08 <-----------------THIS IS THE PROBLEM
00103$:
; C:\SportsSc\sports.c 713
mov a,r3
dec a
; Peephole 105 removed redundant mov
mov r4,a
add a,#_RomTemp
mov r0,a
mov ar5,@r0
mov a,r2
xrl ar5,a
mov a,r5
; Peephole 180 changed mov to clr
; Peephole 186 optimized movc sequence
mov dptr,#_CRCTABLE
movc a,@a+dptr
mov r2,a
mov ar3,r4
mov a,r3
; Peephole 109 removed ljmp by inverse jump logic
jnz 00103$
00108$:
; C:\SportsSc\sports.c 715
mov dpl,r2
00104$:
ret

Discussion

  • Bernhard Held
    Bernhard Held
    2002-07-24

    Logged In: YES
    user_id=203539

    Could you please show us your definition for CRCTABLE and
    RomTemp? What sdcc version?

    Using 2.3.2 and
    unsigned char code CRCTABLE[256];
    unsigned char RomTemp[256];
    doesn't reproduce the problem:
    > mov r3,#0x00

     
  • Johan Knol
    Johan Knol
    2003-01-07

    • milestone: --> unreproducable
    • priority: 5 --> 2
     
  • Johan Knol
    Johan Knol
    2003-01-24

    • status: open --> closed