PDA

View Full Version : Match (assembly)


comrade
07-13-2002, 01:11 AM
Here's a routine to match a string (case-sensitive) like "comrade" against a mask like "co*de":
match proc pszMask:PTR BYTE, pszString:PTR BYTE
push esi
push edi
push ebx
mov esi, [pszMask]
mov edi, [pszString]
xor ebx, ebx
jmp @@chkz
@@next: movzx eax, byte ptr [esi]
cmp eax, "*"
jne @@cmp1
inc ebx
inc esi
jmp @@chkz
@@cmp1: test ebx, ebx
jz @@nowc
mov edx, esi
mov ecx, edi
@@cmp2: movzx eax, byte ptr [edx]
cmp eax, "*"
je @@cmp3
test eax, eax
jz @@cmp3
cmp eax, "?"
je @@sc
cmp al, [ecx]
jne @@cmp3
@@sc: inc edx
inc ecx
jmp @@cmp2
@@cmp3: je @@cmp4
inc edi
cmp byte ptr [edi], 0
jnz @@next
xor eax, eax
jmp @@quit
@@cmp4: xor ebx, ebx
jmp @@mtch
@@nowc: cmp eax, "?"
je @@mtch
cmp al, [edi]
je @@mtch
xor eax, eax
jmp @@quit
@@mtch: xor ebx, ebx
inc esi
inc edi
@@chkz: cmp byte ptr [esi], 0
jne @@next
xor eax, eax
inc eax
cmp byte ptr [edi], 0
je @@quit
mov eax, ebx
@@quit: pop ebx
pop edi
pop esi
ret
match endp

Attached is a working example using this function. I've done little testing and fear this routine is buggy.

file13
07-15-2002, 12:36 PM
uh chief, what assembler is that and what OS? :)

comrade
08-25-2002, 03:18 PM
x86 assembly (32-bit). The example is Win32.