Unicode strings in Assembler - help to debug macro!

Started by themaster, May 06, 2012, 11:23:23 AM

Previous topic - Next topic

themaster

Recently I found a macro, which allows to define unicode strings in ansi source files. It's original code is on russian-language page here:
http://www.cyberforum.ru/assembler/thread340298.html
But - it use uncompartible macro mnemonics and I can not assemble my source file with this macro.
I found, that irpc is deprecate, and replaced it to 'for'. But - two strings of macro still generates error messages.
Macro code is:

du  macro string
local bslash
bslash = 0
    for c, <string>
    if bslash eq 0
if 0 eq 1 ; string to replace buggy next one;
;        if '&c' eq "/" - this string generates error message "Must be a constant integer expression" if uncommented
            bslash = 1
        elseif 0 gt 127  ; string to replace buggy next one;
;        elseif '&c' gt 127 - this string generated the same error message
        db ('&c'- 0B0h),4
        else
        dw '&c'
        endif
    else
           bslash = 0
           if '&c' eq "n"      ; but - this string is not generating error message!
           DW 0Dh,0Ah
           elseif '&c' eq "/"
           dw '/'
           elseif '&c' eq "r"
           dw 0Dh
           elseif '&c' eq "l"
           dw 0Ah
           elseif '&c' eq "s"
           dw 20h
           elseif '&c' eq "c"
           dw 3Bh
           elseif '&c' eq "t"
           dw 9
       endif
    endif
endm
;dw 0 - this string also generate error message... but - I can add terminating null manually.
endm

Please help to debug this macro, if it is not very difficult?
Source code is attached.

Vortex

Hi themaster,

Welcome to the forum.

You don't need a macro to define UNICODE strings. The dw directive does the job :


.386
.model flat,stdcall
option casemap:none

includelib  \PellesC\lib\Win\kernel32.lib
includelib  \PellesC\lib\Win\user32.lib

MessageBoxW PROTO :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess PROTO :DWORD

MB_OK equ 0

.data

capt    dw 'Hello',0
message dw 'This a UNICODE test',0

.code

start:

    invoke  MessageBoxW,0,ADDR message,ADDR capt,MB_OK
    invoke  ExitProcess,0

END start
Code it... That's all...

themaster


LeraUnu

Hi Vortex,

I know it is an old topic...
If I change the message to display:
message dw 'This a UNICODE test ă, â, î, ș, ț',0
the message box doesn't display correctly.
Even if I change the encoding of the source file to UTF-16LE
nothing happens.


Can you help me?

Thank you!

TimoVJL

In UTF8 file
pFile      00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F    Value          
00000000    EF BB BF 6D 65 73 73 61  67 65 20 64 77 20 27 54    message dw 'T
00000010    68 69 73 20 61 20 55 4E  49 43 4F 44 45 20 74 65    his a UNICODE te
00000020    73 74 20 C4 83 2C 20 C3  A2 2C 20 C3 AE 2C 20 C8    st ă, â, î, È
00000030    99 2C 20 C8 9B 27 2C 30  0D 0A     ™, È›',0..
In UTF16 file
pFile      00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F    Value          
00000000    FF FE 6D 00 65 00 73 00  73 00 61 00 67 00 65 00    ÿþm.e.s.s.a.g.e.
00000010    20 00 64 00 77 00 20 00  27 00 54 00 68 00 69 00     .d.w. .'.T.h.i.
00000020    73 00 20 00 61 00 20 00  55 00 4E 00 49 00 43 00    s. .a. .U.N.I.C.
00000030    4F 00 44 00 45 00 20 00  74 00 65 00 73 00 74 00    O.D.E. .t.e.s.t.
00000040    20 00 03 01 2C 00 20 00  E2 00 2C 00 20 00 EE 00     ...,. .â.,. .î.
00000050    2C 00 20 00 19 02 2C 00  20 00 1B 02 27 00 2C 00    ,. ...,. ...'.,.
00000060    30 00 0D 00 0A 00     0.....
In object file
pFile      00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F    Value          
000000EB    48 00 65 00 6C 00 6C 00  6F 00 00 00 54 00 68 00    H.e.l.l.o...T.h.
000000FB    69 00 73 00 20 00 61 00  20 00 55 00 4E 00 49 00    i.s. .a. .U.N.I.
0000010B    43 00 4F 00 44 00 45 00  20 00 74 00 65 00 73 00    C.O.D.E. .t.e.s.
0000011B    74 00 20 00 C4 00 83 00  2C 00 20 00 C3 00 A2 00    t. .Ä.ƒ.,. .Ã.¢.
0000012B    2C 00 20 00 C3 00 AE 00  2C 00 20 00 C8 00 99 00    ,. .Ã.®.,. .È.™.
0000013B    2C 00 20 00 C8 00 9B 00  00 00     ,. .È.›...
May the source be with you

LeraUnu

Hi TimoVJL,

Thank you for your answer.
Unfortunately I don't know how to generate an object file with the correct string.
In a C project I can define UNICODE and _UNICODE symbols, set the encoding of the source files to UTF-16LE and everything is ok.
In asm I don't know how ...

Vortex

Hello LeraUnu,

Quoteset the encoding of the source files to UTF-16LE and everything is ok.

That didn't work for me. Tested with PellesC V13. I receive the uncorrect text display.
Code it... That's all...

TimoVJL

I just analyzed things with pope.exe and TLPEView.exe
Just checking object file .data section, something is really wrong.
So use those tools to check how things went.
May the source be with you

LeraUnu

Hi Vortex,

Here is a small C project test. Please have a look.

Vortex

Hi LeraUnu,

Thanks, your example works fine but my Poasm test is always failing.

- What is the version of your Pelles C setup? Mine is 13
- What's the encoding of your Pelles C editor? Mine is UTF16-LE

Could you check the attachment? I guess my source file cannot correctly encode those special characters.
Code it... That's all...

LeraUnu

Hi Vortex,

Thank you for testing.

PellesC version = 13
Encoding = UTF-16LE

I attach a text file with the Romanian characters and a modified object file (manually)

Michele

Quote from: Vortex on Today at 12:06:24 PMHi LeraUnu,

Thanks, your example works fine but my Poasm test is always failing.

- What is the version of your Pelles C setup? Mine is 13
- What's the encoding of your Pelles C editor? Mine is UTF16-LE

Could you check the attachment? I guess my source file cannot correctly encode those special characters.

It seems that the assembler doesnt' encode properly the unicode text strings.
Replacing the special unicode characters with their respective hex values it works.