1#include <asm.inc> 2#if 0 3 page ,132 4 title strnicmp - compare n chars of strings, ignore case 5;*** 6;strnicmp.asm - compare n chars of strings, ignoring case 7; 8; Copyright (c) Microsoft Corporation. All rights reserved. 9; 10;Purpose: 11; defines __ascii_strnicmp() - Compares at most n characters of two 12; strings, without regard to case. 13; 14;******************************************************************************* 15 16 .xlist 17 include cruntime.inc 18 .list 19 20page 21;*** 22;int __ascii_strnicmp(first, last, count) - compares count char of strings, 23; ignore case 24; 25;Purpose: 26; Compare the two strings for lexical order. Stops the comparison 27; when the following occurs: (1) strings differ, (2) the end of the 28; strings is reached, or (3) count characters have been compared. 29; For the purposes of the comparison, upper case characters are 30; converted to lower case. 31; 32; Algorithm: 33; int 34; _strncmpi (first, last, count) 35; char *first, *last; 36; unsigned int count; 37; { 38; int f,l; 39; int result = 0; 40; 41; if (count) { 42; do { 43; f = tolower(*first); 44; l = tolower(*last); 45; first++; 46; last++; 47; } while (--count && f && l && f == l); 48; result = f - l; 49; } 50; return(result); 51; } 52; 53;Entry: 54; char *first, *last - strings to compare 55; unsigned count - maximum number of characters to compare 56; 57;Exit: 58; returns <0 if first < last 59; returns 0 if first == last 60; returns >0 if first > last 61; 62;Uses: 63; 64;Exceptions: 65; 66;******************************************************************************* 67#endif 68 69 .code 70 71 public ___ascii_strnicmp 72.PROC ___ascii_strnicmp 73// Prolog. Original sources used ML's extended PROC feature to autogenerate this. 74 push ebp 75 mov ebp, esp 76 push edi // uses edi esi ebx 77 push esi 78 push ebx 79#define first ebp + 8 // first:ptr byte 80#define last ebp + 12 // last:ptr byte 81#define count ebp + 16 // count:IWORD 82 83 mov ecx,[count] // cx = byte count 84 or ecx,ecx 85 jz toend // if count = 0, we are done 86 87 mov esi,[first] // si = first string 88 mov edi,[last] // di = last string 89 90 mov bh,'A' 91 mov bl,'Z' 92 mov dh,'a'-'A' // add to cap to make lower 93 94 align 4 95 96lupe: 97 mov ah,[esi] // *first 98 99 or ah,ah // see if *first is null 100 101 mov al,[edi] // *last 102 103 jz short eject // jump if *first is null 104 105 or al,al // see if *last is null 106 jz short eject // jump if so 107 108 add esi,1 // first++ 109 add edi,1 // last++ 110 111 cmp ah,bh // 'A' 112 jb short skip1 113 114 cmp ah,bl // 'Z' 115 ja short skip1 116 117 add ah,dh // make lower case 118 119skip1: 120 cmp al,bh // 'A' 121 jb short skip2 122 123 cmp al,bl // 'Z' 124 ja short skip2 125 126 add al,dh // make lower case 127 128skip2: 129 cmp ah,al // *first == *last ?? 130 jne short differ 131 132 sub ecx,1 133 jnz short lupe 134 135eject: 136 xor ecx,ecx 137 cmp ah,al // compare the (possibly) differing bytes 138 je short toend // both zero; return 0 139 140differ: 141 mov ecx,-1 // assume last is bigger (* can't use 'or' *) 142 jb short toend // last is, in fact, bigger (return -1) 143 neg ecx // first is bigger (return 1) 144 145toend: 146 mov eax,ecx 147 148// Epilog. Original sources used ML's extended PROC feature to autogenerate this. 149 pop ebx 150 pop esi 151 pop edi 152 pop ebp 153 154 ret // _cdecl return 155 156.ENDP // ___ascii_strnicmp 157 end 158