News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

__UNICODE__ equ 1

Started by jj2007, November 01, 2020, 10:44:15 AM

Previous topic - Next topic

jj2007

If unicode is not defined, the output is   Hello world, 100 is the sum
If unicode is defined, the output is        Hello world, 〱0 is the sum

What am I doing wrong?

__UNICODE__     equ     1
include \masm32\include\masm32rt.inc

.data
MyArray dd 25, 18, 23, 17, 9, 2, 6

.code
start:
  print "Hello world, "
  xor ebx, ebx ; set two non-volatile
  xor esi, esi ; registers to zero
  .Repeat
add esi, MyArray[4*ebx]
inc ebx
  .Until ebx>=lengthof MyArray
  inkey str$(esi), " is the sum"
  exit
end start

kiptron

 Should be ebx+4  not ebx*4  ??   Kiptron

Vortex

Hello,

On Windows 10, the output displays a question mark symbol inside a square.

Biterider

Hi
QuoteOn Windows 10, the output displays a question mark symbol inside a square.
This usually happens when an Unicode code point cannot be properly resolved or displayed.
This can happen when you mix Unicode text with Ansi functions or vice versa.

Biterider

jj2007

Quote from: Biterider on November 01, 2020, 08:07:08 PMwhen you mix Unicode text with Ansi functions or vice versa

So, despite the Unicode def on top, str$() remains Ansi??

Vortex

Hello,

QuoteThis can happen when you mix Unicode text with Ansi functions or vice versa.

I didn't mix anything. I guess there is a problem with the print macro used by inkey :


__UNICODE__     equ     0

include \masm32\include\masm32rt.inc

.code

start:

    inkey    str$(100), " test1"
    invoke  ExitProcess,0

END start


I get the same question mark symbol here.

TouEnMasm

There is numerous macros who can change with UNNICODE.
Made a listing of your code or use dumpbin /DISASM to made appear the problem.
Fa is a musical note to play with CL

Biterider

Hi
On my distribution, the macros.asm contains the str$ macro, that looks like:
str$ MACRO DDvalue
  LOCAL rvstring
  .data
    rvstring db 20 dup (0)
    align 4
  .code
  invoke dwtoa,DDvalue,ADDR rvstring
  EXITM <ADDR rvstring>
ENDM


Finally looking for dwtoa, I found it in MASM32\m32lib. This proc is intended for Ansi chars.

Biterider


Vortex

Hi Jochen,

Replacing str$ with ustr$ solves the problem :

inkey ustr$(esi), " is the sum"

Reading macros.asm :

; -----------------------------------------
    ; MSVCRT ASCII & UNICODE integer conversion
    ; -----------------------------------------
      ustr$ MACRO number
        LOCAL buffer
        .data?
          buffer TCHAR 40 dup (?)
          align 4
        .code
        IFNDEF __UNICODE__
          invoke crt__itoa,number,ADDR buffer,10
        ELSE
          invoke crt__itow,number,ADDR buffer,10
        ENDIF
        EXITM <eax>
      ENDM

      sstr$ MACRO number
        LOCAL buffer
        .data?
          buffer TCHAR 40 dup (?)
          align 4
        .code
        IFNDEF __UNICODE__
          invoke crt__ltoa,number,ADDR buffer,10
        ELSE
          invoke crt__ltow,number,ADDR buffer,10
        ENDIF
        EXITM <eax>
      ENDM

jj2007

Quote from: Vortex on November 01, 2020, 09:21:46 PMReplacing str$ with ustr$ solves the problem

Right. For MasmBasic, I've chosen to implement separately Str$() and wStr$(). The idea to declare once on top "this is Unicode, folks" is cute but it's a can of worms. Does anybody here on the forum have a source that has __UNICODE__ equ 1 on top and more than a hundred lines? I doubt it.

hutch--

Out of luck here, I have a full unicode editor but it was done before the equate. It uses the unicode functions in the masm32 library.