flat assembler
Message board for the users of flat assembler.

Index > Main > sub-string parsing macro

Author
Thread Post new topic Reply to topic
Paul6253



Joined: 19 Oct 2003
Posts: 31
Location: NY
Paul6253
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...




Code:

 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 Wink
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

}








    

_________________
Plez xcuce mi spelng
Post 07 Feb 2004, 14:07
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
This would rather be function to do it, not macro Smile
Sub-string search macro would be some pre-processor operation at assembly time using fasm's macro language Smile

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 19 Feb 2004, 04:41
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
yes, each time you use it that code will be generated again.
Post 19 Feb 2004, 19:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.