Reactos
at master 145 lines 3.9 kB view raw
1#include <asm.inc> 2#if 0 3 page ,132 4 title memicmp - compare blocks of memory, ignore case 5;*** 6;memicmp.asm - compare memory, ignore case 7; 8; Copyright (c) Microsoft Corporation. All rights reserved. 9; 10;Purpose: 11; defines __ascii_memicmp() - compare two blocks of memory for lexical 12; order. Case is ignored in the comparison. 13; 14;******************************************************************************* 15 16 .xlist 17 include cruntime.inc 18 .list 19 20page 21;*** 22;int __ascii_memicmp(first, last, count) - compare two blocks of memory, ignore case 23; 24;Purpose: 25; Compares count bytes of the two blocks of memory stored at first 26; and last. The characters are converted to lowercase before 27; comparing (not permanently), so case is ignored in the search. 28; 29; Algorithm: 30; int 31; _memicmp (first, last, count) 32; char *first, *last; 33; unsigned count; 34; { 35; if (!count) 36; return(0); 37; while (--count && tolower(*first) == tolower(*last)) 38; { 39; first++; 40; last++; 41; } 42; return(tolower(*first) - tolower(*last)); 43; } 44; 45;Entry: 46; char *first, *last - memory buffers to compare 47; unsigned count - maximum length to compare 48; 49;Exit: 50; returns <0 if first < last 51; returns 0 if first == last 52; returns >0 if first > last 53; 54;Uses: 55; 56;Exceptions: 57; 58;******************************************************************************* 59#endif 60 61 .code 62 63 public ___ascii_memicmp 64.PROC ___ascii_memicmp 65 66// Prolog. Original sources used ML's extended PROC feature to autogenerate this. 67 push ebp 68 mov ebp, esp 69 push edi 70 push esi 71 push ebx 72#define first ebp + 8 73#define last ebp + 12 74#define count ebp + 16 75 76 mov ecx,[count] // cx = count 77 or ecx,ecx 78 jz short toend // if count=0, nothing to do 79 80 mov esi,[first] // si = first 81 mov edi,[last] // di = last 82 83 // C locale 84 85 mov bh,'A' 86 mov bl,'Z' 87 mov dh,'a'-'A' // add to cap to make lower 88 89 align 4 90 91lupe: 92 mov ah,[esi] // ah = *first 93 add esi,1 // first++ 94 mov al,[edi] // al = *last 95 add edi,1 // last++ 96 97 cmp ah,al // test for equality BEFORE converting case 98 je short dolupe 99 100 cmp ah,bh // ah < 'A' ?? 101 jb short skip1 102 103 cmp ah,bl // ah > 'Z' ?? 104 ja short skip1 105 106 add ah,dh // make lower case 107 108skip1: 109 cmp al,bh // al < 'A' ?? 110 jb short skip2 111 112 cmp al,bl // al > 'Z' ?? 113 ja short skip2 114 115 add al,dh // make lower case 116 117skip2: 118 cmp ah,al // *first == *last ?? 119 jne short differ // nope, found mismatched chars 120 121dolupe: 122 sub ecx,1 123 jnz short lupe 124 125 jmp short toend // cx = 0, return 0 126 127differ: 128 mov ecx,-1 // assume last is bigger 129 // *** can't use "or ecx,-1" due to flags *** 130 jb short toend // last is, in fact, bigger (return -1) 131 neg ecx // first is bigger (return 1) 132 133toend: 134 mov eax,ecx // move return value to ax 135 136// Epilog. Original sources used ML's extended PROC feature to autogenerate this. 137 pop ebx 138 pop esi 139 pop edi 140 pop ebp 141 142 ret // _cdecl return 143 144.ENDP // ___ascii_memicmp 145 end