News:

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

Main Menu

Yet Another Invoke Macro ...

Started by rrr314159, January 29, 2015, 07:44:42 PM

Previous topic - Next topic

rrr314159

Well, it's not that there's anything wrong with printf. There's a lot of misinformation around - you can read that real arguments are always passed in xmm0..xmm3 (under the new Windows x64 calling conventions) but that's not the case. VARARG functions, like printf, use the GPR's instead, also some others - go to the source (MSDN) for the correct info.

Yes, JWasm does xmm registers correctly - but you're reading too fast! I said "Ymm" type is incorrect in JWasm 2.11.

FWIW actually I don't think time is wasted beating one's head against code - that's what it's all about - in coding, persistence is much more important than perspicuity  :biggrin:
I am NaN ;)

GoneFishing

Quote from: rrr314159 on February 01, 2015, 05:31:11 AM
...
Yes, JWasm does xmm registers correctly - but you're reading too fast! I said "Ymm" type is incorrect in JWasm 2.11.
...
oops. sorry ... where is my glasses :icon_eek:?

jj2007

Quote from: rrr314159 on February 01, 2015, 04:06:41 AMps. I think I'll look into converting deb to 64 bits,  I need (at least some of) that capability.

Lines 9533ff in \Masm32\MasmBasic\MasmBasic.inc - it wasn't meant for open source teamwork, though :bgrin:
PM me if you need details.

rrr314159

Hmmmm ... beginning to sound like work! I just want to get some of the printing routines, didn't realize it was part of such a large package. Probably calls other routines, that call other routines, that call ... Well, I'll probably just borrow some techniques, as I did with qword's so-called "Simple" Math.  You guys have churned out a lot of lines!
I am NaN ;)

GoneFishing

@rrr:
      check this thread for some open source printing routines.
I wonder if storing the contents of XMM register in double QWORD at memory location and printing it out as 2 QWORDs sequentially is the only way to dump XMM to console. 

jj2007

Quote from: vertograd on February 02, 2015, 03:26:04 AMI wonder if storing the contents of XMM register in double QWORD at memory location and printing it out as 2 QWORDs sequentially is the only way to dump XMM to console.

Depends on what you want to know:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  sub esp, OWORD      ; create a slot
  fldpi
  fld st
  fstp REAL8 ptr [esp]
  fstp REAL8 ptr [esp+8]
  movups xmm0, [esp]
  deb 4, "2*PI", f:xmm0, d:xmm0, x:xmm0, b:xmm0
  add esp, OWORD
  Exit
end start


Output:

2*PI
f:xmm0          3.141592653589793  <<< lower qword as REAL8 aka double
d:xmm0          4614256656552045848  <<< same as integer
x:xmm0          400921FB 54442D18 400921FB 54442D18  <<< full 128 bits as hex, as in Olly
b:xmm0          01010100010001000010110100011000  <<< 32 bits

GoneFishing

Quote from: jj2007 on February 02, 2015, 05:52:19 AM
...
Depends on what you want to know:
...
I want to know how to print the content of XMM register in several ways.
At the moment I know this:
XMM ->double QWORD variable->GPR-> print(f)
Had no luck with this:
XMM->print(f)
and this:
XMM->stack->print(f)
I'm sure that another way of doing this is possible and it doesn't depend on anything (sort of "Ding an sich")



jj2007

Quote from: vertograd on February 02, 2015, 07:03:24 AMXMM->stack->print(f)

At least this one is simple:
include \masm32\include\masm32rt.inc
.686p
.xmm

.code
o1 OWORD 12345678abcdef0112345678abcdef02h
start:
  movups xmm0, o1
  pshufd xmm0, xmm0, 00011011b
  sub esp, OWORD
  movups [esp], xmm0
  REPEAT 4
pop eax
print hex$(eax), " "
  ENDM
  exit
end start


Output: 12345678 ABCDEF01 12345678 ABCDEF02

GoneFishing

Thanks Jochen  :t
It works on Linux in the following modification:

        INCLUDE fc.asm  ; FCALLTEST macros set
.data
    frm db "%x",0
    o1 OWORD 12345678abcdef0012345678abcdef00h
.code
_start:
        movups xmm0, o1
        sub rsp, OWORD
        movups [rsp], xmm0
        mov r15,3
        .REPEAT
       FCALLTEST printf,offset frm,[rsp+4*r15]
       dec r15
        .UNTIL r15==-1
        FCALLTEST exit,0     
end _start


OUTPUT:
Quote12345678abcdef0012345678abcdef00

XMM->stack->print(f) variant is done!

jj2007

- you can probably use .UNTIL Sign? instead of .UNTIL r15==-1
- don't forget add rsp, OWORD (my version does 4 pops, so no need for that)

GoneFishing

Yes,you're right , UNTIL SIGN? is much better and stack is restored:
      INCLUDE fc.asm  ; FCALLTEST macros set
.data
    frm db "%x",0
    o1 OWORD 12345678abcdef0012345678abcdef00h
.code
_start:
        movups xmm0, o1
        sub rsp, OWORD
        movups [rsp], xmm0
        mov r15,3
        .REPEAT
       FCALLTEST printf,offset frm,[rsp+4*r15]
       dec r15
        .UNTIL SIGN?

        add rsp, OWORD

        FCALLTEST exit,0 
   
end _start   

GoneFishing

One question  that I'm asking myself:
Why cannot I  print the double QWORD value in 2 interations instead of 4?
At the start the stack is aligned to 16 bits . Maybe something in FCALLTEST macro ? :icon_confused:



rrr314159

Why not this?:
include \myinc\inc64.inc
.data
    o1 OWORD 12335678aacdff0112344678abbeef02h
.code

start:
mov r15, 3
@@:
    mov eax, DWORD PTR o1[r15*4]
    prnt "%x ", eax
    dec r15
    jge @B
prnt "\n"

; or, if you wish, a second suggestion:
prnt "%x %x %x %x\n", DWORD PTR o1[12], DWORD PTR o1[8], DWORD PTR o1[4], DWORD PTR o1

ret
end start

Notes:
- I'm using my inc64.inc with my "prnt" macro, equiv to masm32rt.inc print or FC printf.
- Have to use "DWORD PTR" - but surely that's simpler than using both xmm0 AND rsp?
- requires /LARGEADDRESSAWARE:NO linker switch.

As I was about to post u asked to print in 2 interations instead of 4. U know, you could use (with my prnt function, I'm sure FC can do similar) the 2nd suggestion, do it in one line.

[edit] woops, read above posts more carefully. I see you want to print out xmm0 directly, NOT o1 - that's just a value to init xmm0 with. Sorry - where is my glasses ?? :icon_eek:
I am NaN ;)

rrr314159

Well, how about this?include \myinc\inc64.inc
.data
    o1 OWORD 12335678aacdff0112344678abbeef02h
.code

start:
mov r15, 1
@@:
    mov rax, qword ptr o1[r15*8]
    prnt "%llx ", rax
    dec r15
    jge @B
prnt "\n"
ret
end start


prntxmm.asm: 16 lines, 2 passes, 0 ms, 0 warnings, 0 errors
12335678aacdff01 12344678abbeef02


Forgot u wanted it on the stack (I'm in a hurry):include \myinc\inc64.inc
.data
    o1 OWORD 12335678aacdff0112344678abbeef02h
.code

start:
    movups xmm0, o1
    movups [rsp-16], xmm0
    mov r15, [rsp-8]
    mov r14, [rsp-16]
    prnt "%llx ", QWORD PTR r14
    prnt "%llx \n", QWORD PTR r15
ret
end start

I am NaN ;)

GoneFishing

@rrr:
      Thanks for posting your examples. Your "2-iterations"  and "stack" routines work nicely here but especially I appreciate your "second suggestion" to do it in one line  :icon14:
Yes, my macro can do that too:
FCALLTEST printf, offset frm1, qword ptr o1[12], qword ptr o1[8], qword ptr o1[4], qword ptr o1
moreover it can take the values from the stack:
FCALLTEST printf, offset frm1, qword ptr [rsp+12], qword ptr [rsp+8], qword ptr [rsp+4], qword ptr [rsp]

I'm going to write PRINT macro to avoid such a long line of code:
PRINT XMM0
looks better