Author Topic: Xmm to ASCII  (Read 508 times)

HSE

  • Member
  • *****
  • Posts: 1655
  • <AMD>< 7-32>
Xmm to ASCII
« on: April 04, 2021, 06:48:30 AM »
Hi all!

Some macros to print xmm contents (registers or variables).

In 32 bits tested with UASM32, AsmC (with /Znk option) and ML.

In 64 bits tested with MASM64 SDK and ml64 v14 (required some additional pointers typecasts). Take me some extra hours because invoke macro was not full suited for the job and... in 64 bits calling print function erase xmm registers!!!  :eusa_snooty:

Code: [Select]
i8x$(xmm6) =   1  -2   3   4  -5   6   7   8   9  10 -11  12  13  14  15  16

 u8x$(xmm6) =   1 254   3   4 251   6   7   8   9  10 245  12  13  14  15  16

 i16x$(xmm1) =     1     2     3     4    -5     6     7     8

 u16x$(xmm1) =     1     2     3     4 65531     6     7     8

 i32x$(xmm0) =         -1          2          3          4

 u32x$(xmm0) = 4294967295          2          3          4

 i64x$(xmm4) =                    17                  -200

 u64x$(xmm4) =                    17  18446744073709551416

 real4x$(xmm5) =       1.30       2.70       3.10       4.50

 real8x$(oword1) =               -5.8000              125.4000

Press any key to continue...

Thanks in advance for testing, HSE.
« Last Edit: April 04, 2021, 08:20:19 AM by HSE »

LiaoMi

  • Member
  • ****
  • Posts: 845
Re: Xmm to ASCII
« Reply #1 on: April 04, 2021, 07:21:25 AM »
Hi HSE,

Code: [Select]
i8x$(xmm6) =   1  -2   3   4  -5   6   7   8   9  10 -11  12  13  14  15  16

 u8x$(xmm6) =   1 254   3   4 251   6   7   8   9  10 245  12  13  14  15  16


 i16x$(xmm1) =     1     2     3     4    -5     6     7     8

 u16x$(xmm1) =     1     2     3     4 65531     6     7     8


 i32x$(xmm0) =         -1          2          3          4

 u32x$(xmm0) = 4294967295          2          3          4

 i64x$(xmm4) =                    17                  -200

 u64x$(xmm4) =                    17  18446744073709551416

 real4x$(xmm5) =       1.30       2.70       3.10       4.50

 real8x$(oword1) =               -5.8000              125.4000

Press any key to continue...

Biterider

  • Member
  • ****
  • Posts: 689
  • ObjAsm Developer
    • ObjAsm
Re: Xmm to ASCII
« Reply #2 on: April 04, 2021, 07:24:39 AM »
Hi,
same result here as in the first post.

Biterider

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8326
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Xmm to ASCII
« Reply #3 on: April 04, 2021, 07:29:30 AM »
You can expect the invoke macro to work on 64 bit and smaller data sizes, that is how the Microsoft x64 ABI is designed. When you use larger data types you either pass by register (128 or 256 bit) or you pass by address of the data with 64 bit pointers.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 11449
  • Assembler is fun ;-)
    • MasmBasic
Re: Xmm to ASCII
« Reply #4 on: April 04, 2021, 07:33:57 AM »
I have no doubt that your macros work, Hector, but why so many different macros? One is enough. Watch the type of variable thread :cool:

Code: [Select]
include \masm32\MasmBasic\MasmBasic.inc
  SetGlobals v1:QWORD=1234567890123456789, v2:REAL8=1234567890123456789.0
  Init
  Print Str$("v1 as int\t%i\n", v1)
  Print Str$("v2 as real\t%Jf\n", v2)
  movlps xmm0, v1
  Print Str$("Xmm0 qword\t%i\n", xmm0)
  movlps xmm0, v2
  Print Str$("Xmm0 Real8/i\t%i\n", f:xmm0)
  Print Str$("Xmm0 Real8/f\t%Jf\n", f:xmm0)
  fild v1
  Print Str$("ST(0), fild\t%i\n", ST(0)v)
  fld v2
  Print Str$("ST(0), fld\t%Jf\n", ST(0)v)
  mov eax, dword ptr v1
  mov edx, dword ptr v1[4]
  Inkey Str$("edx::eax\t%i\n", edx::eax)
EndOfCode

Output:
Code: [Select]
v1 as int       1234567890123456789
v2 as real      1234567890123456768.
Xmm0 qword      1234567890123456789
Xmm0 Real8/i    1234567890123456768
Xmm0 Real8/f    1234567890123456768.
ST(0), fild     1234567890123456789
ST(0), fld      1234567890123456768.
edx::eax        1234567890123456789

HSE

  • Member
  • *****
  • Posts: 1655
  • <AMD>< 7-32>
Re: Xmm to ASCII
« Reply #5 on: April 04, 2021, 08:38:21 AM »
Thanks LiaoMi and Biterider!

When you use larger data types ...

Ok. It's not the weekend  :biggrin:
The problem was that I'm using smaller data types: bytes, words and dwords.

Output:
Code: [Select]
Xmm0 qword      1234567890123456789
Xmm0 Real8/i    1234567890123456768
Xmm0 Real8/f    1234567890123456768.

Another one :biggrin:
What have to do that with the screen I showed and macros to produce that solution?

Thanks, HSE

jj2007

  • Member
  • *****
  • Posts: 11449
  • Assembler is fun ;-)
    • MasmBasic
Re: Xmm to ASCII
« Reply #6 on: April 04, 2021, 08:47:31 AM »
What have to do that with the screen I showed and macros to produce that solution?

I'm just pointing you to the fact that you are working with a really powerful MACRO assembler. You can hand over multiple types of arguments to a single NumberToString(arg) macro that accepts reg32, xmmreg, global and local variables, even FPU registers. A sequence of IF TYPE(arg) eq DWORD ... ELSEIF TYPE(arg) eq REAL4 ... etc allows you to choose the right actions under the hood. OPATTR, in contrast, allows you to check if the arg is a register, a local or global variable, etc.

Code: [Select]
include \masm32\include\masm32rt.inc
.xmm
.data
MyDD dd 123456789
MySD SDWORD 123456789
MyR4 REAL4 123456789.0
MyQ dq 123456789123456789
MySQ SQWORD 123456789123456789
MyR8 REAL8 123456789.0

TellMeTheType macro arg
Local oa
  if type(arg) eq DWORD
echo arg is a DWORD
  elseif type(arg) eq REAL4
echo arg is a REAL4
  elseif type(arg) eq REAL8
echo arg is a REAL8
  elseif type(arg) eq QWORD
echo arg is a QWORD
  elseif type(arg) eq SQWORD
echo arg is a SQWORD
  elseif type(arg) eq SDWORD
echo arg is a SDWORD
  else
oa = (opattr arg) AND 127
if oa eq 48
echo arg is a register, but the type is unknown
elseif oa eq 36
echo arg is an immediate
else
echo no idea what arg is, sorry
endif
  endif
ENDM

.code
start:
  TellMeTheType MyDD
  TellMeTheType MySD
  TellMeTheType MyR4
  TellMeTheType MyQ
  TellMeTheType MySQ
  TellMeTheType MyR8
  echo --------
  TellMeTheType eax
  TellMeTheType 123
  TellMeTheType xmm0
  TellMeTheType ST(0)
  .err ; we don't need to assemble this, we only want to see the echos
  exit
end start

Note that the Masm32 SDK assembler, MASM version 6.14, does not understand SQWORD. Use MASM 8.0 upwards or a modern assembler like UAsm or AsmC.

HSE

  • Member
  • *****
  • Posts: 1655
  • <AMD>< 7-32>
Re: Xmm to ASCII
« Reply #7 on: April 04, 2021, 09:24:48 AM »
I'm just pointing you to the fact that you are working with a really powerful MACRO assembler. You can hand over multiple types of arguments to a single NumberToString(arg) macro that accepts reg32, xmmreg, global and local variables, even FPU registers. A sequence of IF TYPE(arg) eq DWORD ... ELSEIF TYPE(arg) eq REAL4 ... etc allows you to choose the right actions under the hood. OPATTR, in contrast, allows you to check if the arg is a register, a local or global variable, etc.

I'm not worried. It's  just the weekend. :biggrin:

I think only reading (or writing) the program you can know what there are in an xmm register. No TYPEs. OPATTR nothing to do.

allows you to choose the right actions under the hood.

That is what you can do just selecting a macro  :thumbsup:

jj2007

  • Member
  • *****
  • Posts: 11449
  • Assembler is fun ;-)
    • MasmBasic
Re: Xmm to ASCII
« Reply #8 on: April 04, 2021, 09:27:53 AM »
That is what you can do just selecting a macro  :thumbsup:

Why choose a simple solution if you can have a complicated one, too :tongue:

HSE

  • Member
  • *****
  • Posts: 1655
  • <AMD>< 7-32>
Re: Xmm to ASCII
« Reply #9 on: April 18, 2021, 01:36:11 AM »
Hi All!!

Here a 64 bit versiĆ³n more clean, but that relly in invoke macro promoting real4 to real8 (following x64 ABI).

Regards, HSE.