flat assembler
Message board for the users of flat assembler.

Index > Main > text seek and find

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
is there a way to make it faster?
i'm sure there is one...
Code:
findtext:
;esi=word to find ,0
;edi=text to scan ,0
;return:
;eax=/=0 then not found
;ecx=pointer in text
        xor ecx,ecx    ; ecx=0
.init:
        xor edx,edx
@@:
        mov al,[esi+edx]
        inc edx
        or al,al
        je @f    
        mov ah,[edi+ecx]
        inc ecx
        or ah,ah
        je .end    
        cmp al,ah
        je @b     
        jmp .init
@@:
        sub ecx,edx
        xor ah,ah
        ret
.end:
        or al,1
        ret     
    
Post 10 Jan 2008, 03:05
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
> is there a way to make it faster?
> i'm sure there is one...

Are you sure your code works at all ?

- Place 2 or 4 letters of your word into AX or EAX if long enough
- UTFG String searching algorithm
Post 10 Jan 2008, 03:19
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
i'm sure, i've tested it a couple of minutes ago.
Post 10 Jan 2008, 03:25
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
Code:
    xor ecx,ecx
.0: xor edx,edx
.1: mov ah,[edi+ecx]
    mov al,[esi+edx]
    inc ecx
    inc edx
    cmp al,ah
    je .1
    test al,al
    je .2
    test ah,ah
    jne .0
    or al,1
    ret
.2: sub ecx,edx
    xor ah,ah
    ret    
This looks nice, but doesn't work in some rare instances. Confused

How about?:
Code:
    xor ecx,ecx
    jmp .0
.a: cmp al,ah
    je .1
.0: xor edx,edx
.1: mov ah,[edi+ecx]
    mov al,[esi+edx]
    inc ecx
    inc edx
    test ah,ah
    je .3
    test al,al
    jne .a
    cwb
    sub ecx,edx
    retn
.3: or al,1
    ret    
I like to use the carry flag myself:
Code:
    xor ecx,ecx
    jmp .0
.a: cmp al,ah
    je .1
.0: xor edx,edx
.1: mov ah,[edi+ecx]
    mov al,[esi+edx]
    inc ecx
    inc edx
    test ah,ah
    je .3       ; carry flag clear on jump
    test al,al
    jne .a
    sub ecx,edx
    stc         ; set carry flag to indicate no match
.3: retn    


Last edited by bitRAKE on 10 Jan 2008, 04:09; edited 1 time in total
Post 10 Jan 2008, 03:51
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
wich rare instances?

yeah good job.
but faster if instead of ah, i use cf to say if string was found

faster in post-function treatment.
Code:
or al,al
je @f
...
bad design


jc @f
...
good design
    


Last edited by edfed on 10 Jan 2008, 04:12; edited 1 time in total
Post 10 Jan 2008, 04:09
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
if strings are the same, or pointer same.

(your reply beat my edit Embarassed )
Post 10 Jan 2008, 04:10
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
no, if the string and pointers are the same, it works.
probably, your test program have a problem...
Post 10 Jan 2008, 04:17
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
your third version seems to be slow..
too much jxx
Post 10 Jan 2008, 04:20
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
InHere db "Oh, you just try to match my string!",0,0,0,"junk"
Find db "string!",0,"?"
Post 10 Jan 2008, 05:29
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
as string are null terminated, i don't see the problem.
if strings are sized, then , the algorythm doesn't check for 0, but for counter=0
Code:
findtxt:
        xor ecx,ecx
.init:
        xor edx,edx
@@:
        mov al,[esi+edx]
        inc edx
        or al,al
        je @f
        mov ah,[edi+ecx]
        inc ecx
        or ah,ah
        je .end
        cmp al,ah
        je @b
        jmp .init
@@:
        sub ecx,edx
        mov eax,ecx
        clc
        ret
.end:
        stc
        ret   
    

works even if strings to comapre are the same...
Post 10 Jan 2008, 12:14
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
i am using Boyer-Moore searching algo, pretty fast
Post 18 Jan 2008, 13:43
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
please, don't speak about names of function inventors.
pleaseee, post some code in asm.

ps:
i find the names of humans to name functions is a bad principle. adopted since the antiquity but bad.

because the algorythms exists before to be discovered.
Post 18 Jan 2008, 14:27
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:
please, don't speak about names of function inventors.
pleaseee, post some code in asm.


But that is the algorithm name...http://www.nist.gov/dads/HTML/boyermoore.html http://www.movsd.com/bm.htm
Post 18 Jan 2008, 16:06
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
start: Use scasb to find the first character, then cmp byte per byte till you find a space. If not found jmp start.

or call strstr() from libc. Wink

Code:
invoke LoadLibrary, 'msvcrt.dll'
push eax
invoke GetProcAddress,eax,'_strstr'
mov [strstr],eax
invoke strstr, thetext, thestring
test eax,eax
jz not_found
;eax = pointer to the word you want to find
.
.
.
not_found:
pop eax
invoke FreeLibrary,eax
    


I doubt we can make it any faster than the libc.
Post 18 Jan 2008, 17:12
View user's profile Send private message 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.

Powered by rwasa.