flat assembler
Message board for the users of flat assembler.

Index > Main > Changing strings

Author
Thread Post new topic Reply to topic
denial



Joined: 12 Sep 2004
Posts: 98
denial 27 Oct 2005, 10:19
Hi...

to change the string in a byte array reserved through rb, I always used sprintf from the WinAPI. But as I want to be independent from APIs, I want to use such kind of code from now on:

mov [myvar+0],'A'
mov [myvar+1],'B'
mov [myvar+2],'C'
...

Well its pure and simple, and thus I thought its also fast in execution. But I wanted to know: Is there a way that gets executed faster?

And for copying a string from one var into another, I use this:

mov al,[srcvar+0]
mov [destvar+0],al
mov al,[srcvar+1]
mov [destvar+1],al

How can this be made faster in execution?

Thank you...
Post 27 Oct 2005, 10:19
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 27 Oct 2005, 10:41
There are String operation instructions for such purposes.
Post 27 Oct 2005, 10:41
View user's profile Send private message Visit poster's website Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial 29 Oct 2005, 12:04
thank you. how could i forget about them. Embarassed
i'm sorry...
Post 29 Oct 2005, 12:04
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 01 Nov 2005, 09:29
Code:
        push    ecx edi esi
        mov     esi, src
        mov     edi, dest
        mov     ecx, size
        rep     movsb
        pop     esi edi ecx    
You can even optimize it, and use 'movsd' in 32-bit or 'movsq' in 64-bit
Post 01 Nov 2005, 09:29
View user's profile Send private message Visit poster's website Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 11 Nov 2005, 08:12
Reverend wrote:
Code:
        push    ecx edi esi
        mov     esi, src
        mov     edi, dest
        mov     ecx, size
        rep     movsb
        pop     esi edi ecx    
You can even optimize it, and use 'movsd' in 32-bit or 'movsq' in 64-bit



so which one is it? in code you have movsb... im not at home so i could test it but i want to know before i memorize either one of those... Neutral movsd/movsb...

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 11 Nov 2005, 08:12
View user's profile Send private message MSN Messenger Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 12 Nov 2005, 14:43
The version I posted is correct for all strings (of course for correct arguments). But if you know the string you want to copy is of length dividable by 4 (ie. 4, 8, 12, 16, 20, ...) you can use movsd instruction which copies 4 bytes at once. Then you must also divide size by 4:
Code:
;       if we know that size is dividable by 4
        push    ecx edi esi 
        mov     esi, src 
        mov     edi, dest 
        mov     ecx, size / 4
        rep     movsd
        pop     esi edi ecx    
Post 12 Nov 2005, 14:43
View user's profile Send private message Visit poster's website Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas 13 Nov 2005, 20:58
And remember to align memory variables, for example dword variables should be in addresses divisible by 4 (use the "align" keyword in fasm). This is very important for good performance.
Post 13 Nov 2005, 20:58
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.