Author Topic: qword to unicode?  (Read 3307 times)

HSE

  • Member
  • *****
  • Posts: 2194
  • AMD 7-32 / i3 10-64
qword to unicode?
« on: April 27, 2022, 01:07:01 AM »
Hi All!

Somebody have a 64 bit procedure to convert signed qword integers to unicode string?

Thanks in advance, HSE.
Equations in Assembly: SmplMath

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 9763
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: qword to unicode?
« Reply #1 on: April 27, 2022, 01:10:26 AM »
Hector,

What about one of the MSVC functions ?
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

HSE

  • Member
  • *****
  • Posts: 2194
  • AMD 7-32 / i3 10-64
Re: qword to unicode?
« Reply #2 on: April 27, 2022, 01:35:38 AM »
Hi Hutch!

What about one of the MSVC functions ?

No, because I want that for programs running directly from UEFI.

It's not a critical problem because I can load integer to FPU, and float to unicode work well, but I think a more direct solution could be better.
Equations in Assembly: SmplMath

Biterider

  • Member
  • ****
  • Posts: 975
  • ObjAsm Developer
    • ObjAsm
Re: qword to unicode?
« Reply #3 on: April 27, 2022, 02:22:01 AM »
Hi HSE
What format? Decimal, Hex, Bin?


Biterider
« Last Edit: April 27, 2022, 03:13:36 PM by Biterider »

HSE

  • Member
  • *****
  • Posts: 2194
  • AMD 7-32 / i3 10-64
Re: qword to unicode?
« Reply #4 on: April 27, 2022, 04:28:56 AM »
Hi Biterider!

What format? Decimal, Hex, Bin?

Decimal
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 12958
  • Assembler is fun ;-)
    • MasmBasic
Re: qword to unicode?
« Reply #5 on: April 27, 2022, 05:48:44 AM »
Code: [Select]
include \Masm32\MasmBasic\Res\JBasic.inc ; ## builds in 32- or 64-bit mode with UAsm, ML, AsmC ##
q2aBuffer db 80 dup(?)
.code
q2a:
 push rsi
 push rdi
  mov rsi, offset q2aBuffer+32
  lea rdi, [rsi-32]
  FBSTP REAL10 ptr [rsi]
  mov ecx, REAL10
@@: movzx edx, byte ptr [rsi+rcx]
test edx, edx
je NoNumber
mov al, dl
sar al, 4
and al, 15
add al, "0"
stosw
mov al, dl
and al, 15
add al, "0"
stosw
NoNumber:
dec ecx
jns @B
  pop rdi
  pop rsi
  ret
MyQ QWORD 123456789012345678
Init ; OPT_64 1 ; put 0 for 32 bit, 1 for 64 bit assembly
  PrintLine Chr$("This program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
  fild MyQ
  call q2a
  jinvoke printf, Chr$("Result=%ls"), offset q2aBuffer
EndOfCode

Output:
Code: [Select]
This program was assembled with ml64 in 64-bit format.
Result=123456789012345678

HSE

  • Member
  • *****
  • Posts: 2194
  • AMD 7-32 / i3 10-64
Re: qword to unicode?
« Reply #6 on: April 27, 2022, 07:02:04 AM »
Hi JJ!

Very strange:
Code: [Select]
\Masm32\MasmBasic\Res\JBasic.inc(554) : fatal error A1000:cannot open file : \Masm32\MasmBasic☺That is from command line because RichMasm have some path problem.

Using procedure:
Code: [Select]
  numero  qword 15
result:
Code: [Select]
q2aBuffer = 1F5F [q2u.asm, 226]
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 12958
  • Assembler is fun ;-)
    • MasmBasic
Re: qword to unicode?
« Reply #7 on: April 27, 2022, 07:19:53 AM »
Which assembler?
Does \Masm32\MasmBasic\Res\JBasic.inc exist?
Can you post the code that produces garbage for numero 15?
Here everything works fine, and I see no reason why it shouldn't work :rolleyes:

HSE

  • Member
  • *****
  • Posts: 2194
  • AMD 7-32 / i3 10-64
Re: qword to unicode?
« Reply #8 on: April 27, 2022, 07:42:24 AM »
Which assembler?
Code: [Select]
*** Start D:\masm32\MasmBasic\Res\bldallRM.bat ***
*** 64-bit assembly ***

*** Assemble, link and run q2a ***

*** Assemble using \masm32\bin64\ml64  ***
El sistema no puede encontrar la ruta especificada.
*** Assembly error ***

Does \Masm32\MasmBasic\Res\JBasic.inc exist?
The error is in JBasic.inc

Can you post the code that produces garbage for numero 15?
Code: [Select]
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

% include @Environ(OBJASM_PATH)\Code\Macros\Model.inc   ;Include & initialize standard modules
SysSetup OOP, WIDE_STRING, NUI64, DEBUG(CON)            ;Load OOP files and basic OS support

    .data

        ConInput    CHR 10 DUP(0)                       ;Get some space for the console input buffer
        dBytesRead  DWORD       0

        numero      qword     15
        q2aBuffer   db 80 dup(?)
       
    .code

q2a:
    push rsi
    push rdi
    mov rsi, offset q2aBuffer+32
    lea rdi, [rsi-32]
    FBSTP REAL10 ptr [rsi]
    mov ecx, REAL10
@@: movzx edx, byte ptr [rsi+rcx]
test edx, edx
je NoNumber
mov al, dl
sar al, 4
and al, 15
add al, "0"
stosw
mov al, dl
and al, 15
add al, "0"
stosw
NoNumber:
dec ecx
jns @B
  pop rdi
  pop rsi
  ret

start proc

    SysInit
    DbgClearAll                                           

    fild numero
    call q2a

    DbgStrA q2aBuffer
 
    DbgText "Press \[ENTER\] to continue..."
    invoke CreateFile, $OfsCStr("CONIN$"), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0
    invoke ReadFile, xax, addr ConInput, sizeof(ConInput), addr dBytesRead, NULL

    SysDone
    invoke ExitProcess,0

    ret

start endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end

Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 12958
  • Assembler is fun ;-)
    • MasmBasic
Re: qword to unicode?
« Reply #9 on: April 27, 2022, 09:21:43 AM »
Code: [Select]
*** Start D:\masm32\MasmBasic\Res\bldallRM.bat ***
*** 64-bit assembly ***

*** Assemble, link and run q2a ***

*** Assemble using \masm32\bin64\ml64  ***
El sistema no puede encontrar la ruta especificada.
*** Assembly error ***
So you are using an OPT_Assembler \masm32\bin64\ml64 in your source... sorry, that won't work. RichMasm assumes that all your tools reside in \masm32\bin\*. Copy ml64.exe there, and use OPT_Assembler ml (or let RichMasm use the default \masm32\bin\UAsm64.exe) :cool:

Quote
Does \Masm32\MasmBasic\Res\JBasic.inc exist?
The error is in JBasic.inc

Right - sorry. So what is at the error line 554 in your JBasic.inc, causing fatal error A1000:cannot open file : \Masm32\MasmBasic☺?

Code: [Select]
  Open "I", #0, repargA(fname)
  xchg rsi, rax
  jinvoke GetFileSize, rsi, addr bytesWritten
  inc rax
  xchg rax, rdi           <<<<<<<<<<<<<<<<<<<<<<<<< line 554 <<<<<<<<<<<<<<<<<<
  jinvoke HeapAlloc, MbProHeap, HEAP_GENERATE_EXCEPTIONS, rdi
  mov MbFileReadPtr, rax
  jinvoke ReadFile, rsi, rax, rdi, addr bytesWritten, 0
  mov rdx, MbFileReadPtr

Quote
Can you post the code that produces garbage for numero 15?
Code: [Select]
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
...

I can't see where it fails, can you post the exe, please?

HSE

  • Member
  • *****
  • Posts: 2194
  • AMD 7-32 / i3 10-64
Re: qword to unicode?
« Reply #10 on: April 27, 2022, 09:50:16 AM »
... sorry, that won't work. RichMasm assumes that all your tools reside in \masm32\bin\*

All 64 bits tools are in bin64 folder because Masm64 SDK standard, but not problem. We can wait until you make the corrections  :biggrin: :biggrin: :biggrin:

Right - sorry. So what is at the error line 554 in your JBasic.inc, causing fatal error A1000:cannot open file : \Masm32\MasmBasic☺?

 :biggrin: I have DualMacs.inc but I lost DualWin.inc somewhere. And I never see some pt.inc. For sure I miss some update.

I can't see where it fails, can you post the exe, please?
Adjunted.
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 12958
  • Assembler is fun ;-)
    • MasmBasic
Re: qword to unicode?
« Reply #11 on: April 27, 2022, 06:25:30 PM »
I can't see where it fails, can you post the exe, please?
Adjunted.
Quote
@@:   movzx ecx, byte ptr [rsi+rdx]
   jecxz NoNumber
   mov eax, ecx
   sar al, 4
   and al, 15
   add al, "0"
   stosw

jj2007

  • Member
  • *****
  • Posts: 12958
  • Assembler is fun ;-)
    • MasmBasic
Re: qword to unicode?
« Reply #12 on: April 27, 2022, 08:21:48 PM »
In this forum, beating the CRT by at least a factor 5 is our favourite pastime :biggrin:

Code: [Select]
This program was assembled with ml64 in 64-bit format.
561 ticks for crt swprintf
Result=123456789012345678
109 ticks for q2a
Result=123456789012345678

Code: [Select]
This program was assembled with ml in 32-bit format.
687 ticks for crt swprintf
Result=123456789012345678
109 ticks for q2a
Result=123456789012345678

HSE

  • Member
  • *****
  • Posts: 2194
  • AMD 7-32 / i3 10-64
Re: qword to unicode?
« Reply #13 on: April 27, 2022, 09:54:53 PM »
 :biggrin:
Code: [Select]
numero      qword 5000
Code: [Select]
q2aBuffer = 50 [q2u.asm, 69]
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 12958
  • Assembler is fun ;-)
    • MasmBasic
Re: qword to unicode?
« Reply #14 on: April 27, 2022, 10:24:43 PM »
:biggrin:
Code: [Select]
numero      qword 5000
Code: [Select]
q2aBuffer = 50 [q2u.asm, 69]

Code: [Select]
Result=5000 :biggrin:

Post your exe...