strncmp issue
Channa
channa.kad at gmail.com
Mon May 4 06:52:51 UTC 2009
Hi,
Thanks for the fix.
I used your code and tested it works fine.
But i have one doubt in the code below you have added
:
- cmpcs r2, #1
+ beq 2f
+ cmp r2, #1
:
Instead of the branch instruction above replace the instruction
'cmpcs' with 'cmp'
since we are comparing unsigned value in 'r2' with a constant.
So the code looks as below
:
- cmpcs r2, #1
+ cmp r2, #1
:
I have tested the above fix it works good for me.
Please let me know your views.
Thanks & Regards,
Channa
2009/4/30 Mark Tinguely <tinguely at casselton.net>:
>
>> Yes. We should get the following results:
>>
>> strncmp("a", "b", 0); 0
>> strncmp("a", "b", *); < 0
>>
>> where * is any other number :)
>>
>> Warner
>
> ENTRY(strncmp)
> /* if (len == 0) return 0 */
> cmp r2, #0
> moveq r0, #0
> RETeq
>
> /* ip == last src address to compare */
> add ip, r0, r2
> 1:
> ldrb r2, [r0], #1
> ldrb r3, [r1], #1
> cmp ip, r0
> - cmpcs r2, #1
> + beq 2f
> + cmp r2, #1
> cmpcs r2, r3
> beq 1b
> +2:
> sub r0, r2, r3
> RET
>
> also ip < r0 if r2 = (unsigned int) -1 using 32 bit math. so original
> loop will terminate and compare the first characters. For example
> strncmp("ab", "aa", -1) will result is 0.
>
> I sent Olivier a couple patches, both wrong. Again, sorry for all the noise.
>
> The above code, though, should work in all cases.
>
> strncmp("b", "a", 0) result is 0
> strncmp("abcdef", "abcdef", n) result is 0
> strncmp("abcde", "abcdef", n) 0 if 0 <= n < 6 neg if n < 0 or n > 5
> strncmp("abcdef", "abcde", n) 0 if 0 <= n < 6 pos if n < 0 or n > 5
>
>
> The "beq" will break out of the loop if we give a count <= the string
> length the first arguement.
>
> The next cmp looks for the NULL byte, and the last cmp checks the characters
> in the strings.
>
> --Mark.
>
More information about the freebsd-arm
mailing list