flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Calculate string len and split cmp parts.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1840
Roman 10 Jun 2023, 15:04
I want write macro calculate string len and split camp parts.
Code:
Cmpstring txt,"a","bc","word","sounds01","invisible"
;do

Cmp byte [txt],"a"
Cmp word [txt],"bc"
Cmp dword [txt],"word"
;but how generated chain cmps for "sounds01" or "invisible" ?
Cmp dword [txt],"soun"
Cmp dword [txt+4],"ds01"
;Somehow divided len/4 and get two dwords and one byte for cmp
Cmp dword [txt],"invi"
Cmp dword [txt+4],"sibl"
Cmp byte [txt+8],"e"
    

I do not want write in macro if len = 8 do two cmp.
And write If len = 9 do three cmp.

Because I must write in macro different if for different words.
I don't want do this, because macro Cmpstring will become too big.


Last edited by Roman on 10 Jun 2023, 15:18; edited 4 times in total
Post 10 Jun 2023, 15:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 10 Jun 2023, 15:08
Use a hash of the string as an identifier.

Or:
Code:
rep cmpsb    
Post 10 Jun 2023, 15:08
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1840
Roman 10 Jun 2023, 15:11
Quote:
rep cmpsb

Then I must using edi,esi,ecx.
Sometimes its not handful.

If I have three words I must do three times rep cmpsb

I found memcmp str1,str2,len
Post 10 Jun 2023, 15:11
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4061
Location: vpcmpistri
bitRAKE 11 Jun 2023, 13:02
There is this pattern I like to use: It consists of building a string on the stack (in reverse part order), and then I gather all the parts together:
Code:
macro MULTICATA ; 21 bytes
        local more_strings, more_characters, no_more_strings
more_strings:
        pop rcx
        jrcxz no_more_strings
more_characters:
        mov al, [rcx]
        inc rcx
        test al, al
        jz more_strings
        mov [rdx], al
        inc rdx
        jmp more_characters
no_more_strings:
        mov [rdx], cl
end macro    
... I was wondering if such a pattern might help your work here?

Would it help to programmatically construct your comparison target values on the stack, and then perform the comparison? I am perhaps completely wrong and have wasted your time.
Post 11 Jun 2023, 13:02
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.