1 ! strncmp
() Author
: Kees J. Bot
3 .sect .text; .sect .rom; .sect .data; .sect .bss
5 ! int strncmp
(const char
*s1
, const char
*s2
, size_t ecx
)
16 test ecx
, ecx
! Max length is zero?
18 mov esi
, 8(ebp
) ! esi
= string s1
19 mov edi
, 12(ebp
) ! edi
= string s2
22 cmpsb
! Compare two bytes
24 cmpb
-1(esi
), 0 ! End of string?
26 dec ecx
! Length limit reached?
28 done
: seta al
! al
= (s1
> s2
)
29 setb ah
! ah
= (s1
< s2
)
31 movsxb eax
, al
! eax
= (s1
> s2
) - (s1
< s2
), i.e.
-1, 0, 1