source: trunk/minix/lib/i86/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: 703 bytes
Line 
1! strncmp() Author: Kees J. Bot
2! 27 Jan 1994
3.sect .text; .sect .rom; .sect .data; .sect .bss
4
5! int strncmp(const char *s1, const char *s2, size_t cx)
6! Compare two strings.
7!
8.sect .text
9.define __strncmp
10__strncmp:
11 push bp
12 mov bp, sp
13 push si
14 push di
15 xor ax, ax ! Prepare return value
16 test cx, cx ! Max length is zero?
17 je equal
18 mov si, 4(bp) ! si = string s1
19 mov di, 6(bp) ! di = string s2
20 cld
21compare:
22 cmpsb ! Compare two bytes
23 jne unequal
24 cmpb -1(si), #0 ! End of string?
25 je equal
26 dec cx ! Length limit reached?
27 jne compare
28 jmp equal
29unequal:
30 ja after
31 sub ax, #2 ! if (s1 < s2) ax -= 2;
32after: inc ax ! ax++, now it's -1 or 1
33equal: pop di
34 pop si
35 pop bp
36 ret
Note: See TracBrowser for help on using the repository browser.