flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Easy UTF16 string creation.

Author
Thread Post new topic Reply to topic
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
Hi Everyone,

I've been converting some source code, so that all strings are native UTF-16. Since at the moment all strings are straight ASCII (the 7bit kind), conversion is relatively easy. However rather than doing thing by hand, which can be time consuming, I thought I might as well create a macro to do this...
Code:
macro utf16_pascal_str name, [string]
{
common 
  name:
   local label, label2
 db label-label2
     label:
forward
       dw string
common
 label2:
}

utf16_pascal_str my_string, 'H','e','l','l','o'
    
Generates the correct sequence, however instead of splitting up the string as above, I would just like to use : utf16_pascal_str my_string, 'Hello' to generate the correct sequence. So any hints would be appreciated.

The macro would be something like this:
Code:
macro utf16_pascal_str name, string
{
       name:
   local label, label2
 dw label-label2
     label:
  dw string
   label2:
}    
which is simplier, however the dw string doesn't work, (which is expected as it was never implemented that way).

So how I do take a string as input, and then define a series of dw with each one being a single character?
Post 02 Jan 2005, 12:19
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Use "du" instead of "dw".
Post 02 Jan 2005, 13:12
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
Thanks.
Post 02 Jan 2005, 22:19
View user's profile Send private message Visit poster's website Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
Here is the final version of the macro...
Code:
macro utf16_pascal_str name, [string]
{
common 
      name:
   local label, label2
 dw ( label - label2 ) / 2
   label:
  dw 0feffh ;This is the Unicode Byte Order Mark
forward
   du string
common
 label2:
}    

Usage:
Code:
utf16_pascal_str string2, 02126h, ' This is the symbol for ohm'    

will produce a correctly formatted UTF16 string. eg
Quote:
Ω This is the symbol for ohm

The NULL terminated version would be:
Code:
macro utf16_str name, [string]
{
common 
        name:
   dw 0feffh ;This is the Unicode Byte Order Mark
forward
   du string
common
 dw 0
}    

Same usage applies.

Note: The Pascal version uses a word, instead of a byte for string length. Strings upto 64K characters are now possible (using upto 128K of memory).
Note2: The first word is the Unicode Byte Order Mark, to define the endian mode.
Post 03 Jan 2005, 01:45
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.