source: trunk/minix/lib/i386/string/_strncmp.s@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 711 bytes
Line 
1! strncmp() Author: Kees J. Bot
2! 1 Jan 1994
3.sect .text; .sect .rom; .sect .data; .sect .bss
4
5! int strncmp(const char *s1, const char *s2, size_t ecx)
6! Compare two strings.
7!
8.sect .text
9.define __strncmp
10 .align 16
11__strncmp:
12 push ebp
13 mov ebp, esp
14 push esi
15 push edi
16 test ecx, ecx ! Max length is zero?
17 je done
18 mov esi, 8(ebp) ! esi = string s1
19 mov edi, 12(ebp) ! edi = string s2
20 cld
21compare:
22 cmpsb ! Compare two bytes
23 jne done
24 cmpb -1(esi), 0 ! End of string?
25 je done
26 dec ecx ! Length limit reached?
27 jne compare
28done: seta al ! al = (s1 > s2)
29 setb ah ! ah = (s1 < s2)
30 subb al, ah
31 movsxb eax, al ! eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1
32 pop edi
33 pop esi
34 pop ebp
35 ret
Note: See TracBrowser for help on using the repository browser.