Author Topic: Yet Another Invoke Macro ...  (Read 17756 times)

rrr314159

  • Member
  • *****
  • Posts: 1382
Re: Yet Another Invoke Macro ...
« Reply #15 on: February 01, 2015, 05:31:11 AM »
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

  • Member
  • *****
  • Posts: 1071
  • Gone fishing
Re: Yet Another Invoke Macro ...
« Reply #16 on: February 01, 2015, 06:15:37 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

  • Member
  • *****
  • Posts: 10675
  • Assembler is fun ;-)
    • MasmBasic
Re: Yet Another Invoke Macro ...
« Reply #17 on: February 01, 2015, 07:08:09 AM »
ps. 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

  • Member
  • *****
  • Posts: 1382
Re: Yet Another Invoke Macro ...
« Reply #18 on: February 01, 2015, 07:45:28 AM »
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

  • Member
  • *****
  • Posts: 1071
  • Gone fishing
Re: Yet Another Invoke Macro ...
« Reply #19 on: February 02, 2015, 03:26:04 AM »
@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

  • Member
  • *****
  • Posts: 10675
  • Assembler is fun ;-)
    • MasmBasic
Re: Yet Another Invoke Macro ...
« Reply #20 on: February 02, 2015, 05:52:19 AM »
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.

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

  • Member
  • *****
  • Posts: 1071
  • Gone fishing
Re: Yet Another Invoke Macro ...
« Reply #21 on: February 02, 2015, 07:03:24 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

  • Member
  • *****
  • Posts: 10675
  • Assembler is fun ;-)
    • MasmBasic
Re: Yet Another Invoke Macro ...
« Reply #22 on: February 02, 2015, 07:42:25 AM »
XMM->stack->print(f)

At least this one is simple:
Code: [Select]
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

  • Member
  • *****
  • Posts: 1071
  • Gone fishing
Re: Yet Another Invoke Macro ...
« Reply #23 on: February 02, 2015, 08:41:19 AM »
Thanks Jochen  :t
It works on Linux in the following modification:
Code: [Select]
        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:
Quote
12345678abcdef0012345678abcdef00

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

jj2007

  • Member
  • *****
  • Posts: 10675
  • Assembler is fun ;-)
    • MasmBasic
Re: Yet Another Invoke Macro ...
« Reply #24 on: February 02, 2015, 08:45:40 AM »
- 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

  • Member
  • *****
  • Posts: 1071
  • Gone fishing
Re: Yet Another Invoke Macro ...
« Reply #25 on: February 02, 2015, 08:53:29 AM »
Yes,you're right , UNTIL SIGN? is much better and stack is restored:
Code: [Select]
      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

  • Member
  • *****
  • Posts: 1071
  • Gone fishing
Re: Yet Another Invoke Macro ...
« Reply #26 on: February 02, 2015, 09:58:30 AM »
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

  • Member
  • *****
  • Posts: 1382
Re: Yet Another Invoke Macro ...
« Reply #27 on: February 02, 2015, 10:16:56 AM »
Why not this?:
Code: [Select]
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

  • Member
  • *****
  • Posts: 1382
Re: Yet Another Invoke Macro ...
« Reply #28 on: February 02, 2015, 11:36:21 AM »
Well, how about this?
Code: [Select]
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

Code: [Select]
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):
Code: [Select]
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

  • Member
  • *****
  • Posts: 1071
  • Gone fishing
Re: Yet Another Invoke Macro ...
« Reply #29 on: February 03, 2015, 12:04:33 AM »
@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:
Code: [Select]
FCALLTEST printf, offset frm1, qword ptr o1[12], qword ptr o1[8], qword ptr o1[4], qword ptr o1moreover it can take the values from the stack:
Code: [Select]
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:
Code: [Select]
PRINT XMM0
looks better