#417 error in "while" loop

closed
1
2013-05-25
2002-11-30
No

compiler lets to process the loop contents while the
criterium is not met.

it happened when I tried to use library function "strncmp"
follwing code fails when two different compared strings
have for instance second characters equal while first not.
the return value is 0 then.

c source:

/* copy of Sandeep's "strncmp" from SDCC library */
int instance_strncmp( char *first, char *last, int count)
{
while( --count && *first && *first == *last )
{
first++;
last++;
}

return *first - *last;
}
===================================

asm code:

===================================
ar2 = 0x02
ar3 = 0x03
ar4 = 0x04
ar5 = 0x05
ar6 = 0x06
ar7 = 0x07
ar0 = 0x00
ar1 = 0x01
;
main.c 0
mov r2,dpl
mov r3,dph
mov r4,b
;
main.c 7
mov r5,_instance_strncmp_PARM_2
mov r6,(_instance_strncmp_PARM_2 + 1)
mov r7,(_instance_strncmp_PARM_2 + 2)
00103$:
mov a,_instance_strncmp_PARM_3
add a,#0xff
mov r0,a
mov a,(_instance_strncmp_PARM_3 + 1)
addc a,#0xff
mov r1,a
mov _instance_strncmp_PARM_3,r0
mov (_instance_strncmp_PARM_3 + 1),r1
mov a,r0
orl a,r1
jnz 00112$
ljmp 00105$
00112$:
mov dpl,r2
mov dph,r3
mov b,r4
lcall __gptrget
mov r0,a
inc dptr <--- pointer increased while not sure if criterium
is met
mov r2,dpl
mov r3,dph
mov a,r0
jnz 00113$
ljmp 00105$
00113$:
mov dpl,r5
mov dph,r6
mov b,r7
lcall __gptrget
mov r1,a
inc dptr <--- the same....
mov r5,dpl
mov r6,dph
mov a,r0
cjne a,ar1,00114$
sjmp 00115$
00114$:
ljmp 00105$
00115$:
;
main.c 9
;
main.c 10
ljmp 00103$
00105$:
;
main.c 13
mov dpl,r2
mov dph,r3
mov b,r4
lcall __gptrget
mov r2,a
mov dpl,r5
mov dph,r6
mov b,r7
lcall __gptrget
mov r5,a
clr c
mov a,r2
subb a,r5
mov r2,a
mov a,#0x00
subb a,#0x00
mov r3,a
mov dpl,r2
mov dph,r3
00106$:
ret
========================================

Discussion

  • Johan Knol

    Johan Knol - 2003-01-15
    • milestone: --> unreproducable
    • priority: 5 --> 1
    • assigned_to: nobody --> johanknol
    • summary: error in "while" loop --> error in "while" loop
     
  • Johan Knol

    Johan Knol - 2003-01-15

    Logged In: YES
    user_id=63512

    This can't be reproduced in the latest version

     
  • Johan Knol

    Johan Knol - 2003-01-19
    • status: open --> closed
     
  • Johan Knol

    Johan Knol - 2003-01-19
    • summary: error in "while" loop --> error in "while" loop
     

Log in to post a comment.