flat assembler
Message board for the users of flat assembler.
Index
> Main > how to search for all strings starting with substr? |
Author |
|
a115433 06 Mar 2010, 16:15
create a buffer to wich you put bytes or characters (a,b)
and create a variable that hold number of bytes/chars in this buffer. create also a dynamic structure of addreses - to hold addrs of each string. and variable that hold ammount of those addreses. last think is buffer that holds all strings and its size after each add or substract from character buffer, just refresh address buffer. backspace - you would require backlink to yet another struct, but you can just use primary one (all strings) and chars/bytes in buffer. its quite simple btw, there are no special algoritms like in crypto. |
|||
06 Mar 2010, 16:15 |
|
baldr 06 Mar 2010, 16:34
zhak,
If the list is sorted, binary search can be used to determine range of strings to display. You may store strings in prefix tree, then range is just corresponding subtree. |
|||
06 Mar 2010, 16:34 |
|
zhak 08 Mar 2010, 17:51
i decided to keep things simple. less complicated code contains less bugs. taking into account the fact that user types with speed about 5-6 chars per second, and not very long list of supported commands (less than 30), speed is not on the first place.
i assume user input to be a substring. and i search this substring in every command. if it matches- i display the command. pretty simple, yet effective solution. |
|||
08 Mar 2010, 17:51 |
|
edemko 08 Mar 2010, 19:42
Try post #5:
http://wasm.ru/forum/viewtopic.php?id=35490 |
|||
08 Mar 2010, 19:42 |
|
zhak 08 Mar 2010, 23:11
wasm.ru is online again. it was down for a while
|
|||
08 Mar 2010, 23:11 |
|
edemko 08 Mar 2010, 23:26
Code: ; Searches for a byte pattern in another one. Count from 1. ; result <- eax. ; restore: eflags. ; Both search directions supported but result is always given as if eflags.df=0. ; -str = wanted. ; -lstr = length of str in bytes. ; -src = source. ; -lsrc = length of src in bytes. ; -start = job start relatively src's head(eflags.df=0) or tail(eflags.df=1). ; -stop = job end(wall) relatively src's head(eflags.df=0) or tail(eflags.df=1). proc pos uses ebx ecx edx esi edi, str:dword, lstr:dword, src:dword, lsrc:dword, start:dword, stop:dword pushfd xor eax,eax ; result=0 cdq or edx,[lstr] jz .exit ; length(str)=0 mov ecx,eax or ecx,[lsrc] jz .exit ; length(src)=0 cmp edx,ecx ja .exit ; length(str)>length(src) mov ebx,eax or ebx,[start] jz .exit ; start=0 cmp ebx,ecx ja .exit ; start>length(src) mov esi,eax or esi,[stop] jz @f ; stop=0 cmp esi,ecx ja @f ; stop>length(src) -> stop=0 cmp esi,ebx jbe .exit ; start>=stop lea ecx,[esi-1] ; ecx>0 <- const @@: dec ebx sub ecx,ebx ; ecx>0 <- const dec edx ; cmpsb.ecx sub ecx,edx ; scasb.ecx jbe .exit ; over(src)flow bt dword[esp],10 mov esi,[str] mov edi,[src] lea eax,[edi+ebx] cmovnc edi,eax jnc @f ; search TO bigger address neg ebx add ebx,[lsrc] lea edi,[edi+ebx-1] add esi,edx ; search FROM bigger address @@: lodsb @@: repne scasb jne .fail ; no str[1] in src test edx,edx jz @f ; length(str)=1 -> no need to check the rest(edx) push esi edi mov ebx,ecx mov ecx,edx repe cmpsb pop edi esi je @f ; str rest(edx) match mov ecx,ebx jecxz .fail jmp @b @@: bt dword[esp],10 jnc @f neg edx lea edi,[edi+2+edx]; switch result to be always src's head relative @@: sub edi,[src] mov eax,edi jmp .exit .fail: xor eax,eax .exit: popfd ret endp |
|||
08 Mar 2010, 23:26 |
|
zhak 08 Mar 2010, 23:45
thanks serfasm
this problem is already solved |
|||
08 Mar 2010, 23:45 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.