I needed to do a sub-string search so I decided to challenge myself...
here's a simple macro that works.
I'm looking forward to seeing some optimization/improvements!
later...
macro SubString scanstr,substr,lscanstr,lsubstr
{
;;;;;;;;;;;;;;;;;;;;;SUBSTRING SEARCH MACRO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lea edi,[scanstr] ;scan string
lea esi,[substr] ;sub-string
;counters keep track of ptr boundaries
;so everytime a ptr gets incremented we
;decrement a counter as we are closer to
;a final result some code might seem redun-
;dant but it works thought about using the
;stack but thats just more instructions anyway
;not gonna pick over cycles on a 2.8 ghz cpu
mov ecx,lsubstr ;must be length of substr
mov edx,lscanstr ;must be length of scanstr
parse:
test ecx,ecx ;(ZF)? done : continue
jz found_it ;found the sub-string
test edx,edx
jz not_found
;copy bytes at offsets in each string
mov byte bl,[edi] ;copy byte at [scanstr]
mov byte al,[esi] ;copy byte at [substr]
cmp al,bl ;check for match
je got_1 ;cool
;nope
;reset esi
;reset counter
;and start over
lea esi,[substr]
mov ecx,6
;just in case, check byte for base value of sub-str b4 moving up
cmp byte bl,[esi]
jne try_again
got_1:
inc edi
inc esi
dec ecx
dec edx
jmp parse
try_again:
inc edi
dec edx
jmp parse
}