|
|
1.1 root 1: //////////
2: / i8086 C string library.
3: / strncmp()
4: / ANSI 4.11.4.4.
5: //////////
6:
7: //////////
8: / strncmp(String1, String2, Count)
9: / char *String1, *String2;
10: / int Count;
11: /
12: / Compare up to Count bytes of String1 and String2.
13: //////////
14:
15: #include <larges.h>
16:
17: String1 = LEFTARG
18: String2 = String1+DPL
19: Count = String2+DPL
20:
21: Enter(strncmp_)
22: mov dx, $0 / Result to DX
23: mov cx, Count(bp) / Count to CX
24: or cx, cx
25: je 4f / Zero length, return equal
26: Lds si, String2(bp) / String2 address to DS:SI
27: Les di, String1(bp) / String1 address to ES:DI
28: cld
29:
30: 1: lodsb / String2 character to AL
31: scasb / and compare to String1 character
32: jne 2f / Mismatch
33: orb al, al
34: loopne 1b / Continue if CX!=0 && AL!=0
35: jmp 4f / Match, return 0
36:
37: 2: ja 3f
38: inc dx / String1 > String2, return 1
39: jmp 4f
40:
41: 3: dec dx / String1 < String2, return -1
42:
43: 4: mov ax, dx / Result to AX
44: Leave
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.