flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro to convert string to unicode

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 30 May 2017, 11:02
Hi,

Is it possible to implement a macro like the following:

Code:
CONVERT_TO_UNICODE esi, "My String"    


Which will produce the following code:

Code:
mov word [esi + 0], 'M'
mov word [esi + 2], 'y'
mov word [esi + 4], ' '
mov word [esi + 6], 'S'
mov word [esi + 8], 't'
mov word [esi + 10], 'r'
mov word [esi + 12], 'i'
mov word [esi + 14], 'n'
mov word [esi + 16], 'g'
mov word [esi + 18], 0    


Thanks!
Post 30 May 2017, 11:02
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 30 May 2017, 11:43
Code:
macro CONVERT_TO_UNICODE base*,str*
{
        local ..str,..sz,..ch
        virtual at 0
                ..str:: du str,0
                ..sz = $/2
        end virtual
        repeat ..sz
                load ..ch word from ..str:(%-1)*2
                mov word [base+(%-1)*2],..ch
        end repeat
}    
Post 30 May 2017, 11:43
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 31 May 2017, 09:29
Thanks a lot Tomasz! This is magic for me! Smile

It works great, but I have a project that needs to use old FASM 1.69.29 and it reports the following compilation error:

Error: invalid name
Code:
..str:: du str, 0    


Isn't that construction available for old FASM? I know that I should be punished for using that old version! Smile Is there an equivalent for the old version?

Thanks!
Post 31 May 2017, 09:29
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 31 May 2017, 10:20
It is possible with old version, though suboptimal:
Code:
macro CONVERT_TO_UNICODE base*,str*
{ 
        local ..sz,..ch
        virtual at 0 
                du str,0
                ..sz = $/2 
        end virtual 
        repeat ..sz 
                virtual at 0
                                du str,0
                                load ..ch word from (%-1)*2
                end virtual
                mov word [base+(%-1)*2],..ch 
        end repeat 
}    
Post 31 May 2017, 10:20
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 31 May 2017, 15:38
Thanks again Tomasz! Amazing!!! Smile
Post 31 May 2017, 15:38
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.