News:

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

Main Menu

Qword problem

Started by ragdog, September 06, 2013, 06:46:43 PM

Previous topic - Next topic

ragdog

Hi @All

I need a function to push a qword

example to call this

.Data
My64a   qword   0123456789abcdefh

push My64a
push offset lpdata
call  Test123

Test123 proc Buffer:DWORD,Value:QWORD

I think the macro makes it

http://www.masmforum.com/board/index.php?PHPSESSID=8d46cd4ecb1688be429ab49694ec53e6&topic=6545.msg48706#msg48706


qw2dw macro src:qword, dst:dword
fld [src]
fistp [dst]
endm


But i use this macro have a a error
"error A2008: syntax error : qword"

jj2007

Why do you need a macro??

include \masm32\include\masm32rt.inc

.code
Test123 proc Buffer:DWORD,Value:QWORD
  print "ok"
  ret
Test123 endp

My64a   qword   0123456789abcdefh

start:   invoke Test123, ecx, My64a
   exit

end start

hutch--

If by PUSH you mean pass a 64 bit value directly on the stack rather than push its address, what is wrong with pushing both the high and low DWORDs in the right order if the receiving function knows how to read a 64 bit value from the stack.

jj2007

Indeed. But if you insist on a macro, here is one (pushq works without MasmBasic):

include \masm32\MasmBasic\MasmBasic.inc
pushq MACRO qArg
LOCAL is, c3$
  c3$ CATSTR <qArg>, <xx>
  c3$ SUBSTR c3$, 1, 3
  ifidni c3$, <xmm>
        push eax
        push edx
        movlps qword ptr [esp], qArg
  else
        is INSTR <qArg>, <::>
        if is
                c3$ SUBSTR <qArg>, 1, is-1
                push c3$
                c3$ SUBSTR <qArg>, is+2
                push c3$
        else
                push dword ptr qArg[4]
                push dword ptr qArg
        endif
  endif
ENDM
.code
MyTest proc  qArg:QWORD
  Print Str$("You passed %i\n", qArg)
  ret
MyTest endp

MyQ1        QWORD 1111100000123456789
MyQ2        QWORD 2222200000123456789
MyQ3        QWORD 3333300000123456789
MyQ4        QWORD 4444400000123456789

        Init
        invoke MyTest, MyQ1        ; simplest solution - invoke does the job for you

        pushq MyQ2        ; push a global variable
        call MyTest

        mov eax, dword ptr MyQ3
        mov edx, dword ptr MyQ3[4]
        pushq edx::eax        ; push a reg:reg pair
        call MyTest

        movlps xmm0, MyQ4
        pushq xmm0        ; push xmm...
        call MyTest

        Inkey "OK?"
        Exit
end start


Output:
You passed 1111100000123456789
You passed 2222200000123456789
You passed 3333300000123456789
You passed 4444400000123456789
OK?

dedndave

if you prototype it with a QWORD, you can pass a QWORD

MyFunc PROTO :QWORD

qwMyVal QWORD 123456789ABCDEF0h

INVOKE  MyFunc,qwMyVal

MyFunc PROC qwVal:QWORD

ret

MyFunc ENDP


however, i seem to recall ML v 6.14 and 6.15 having a problem with
qwMyVal QWORD 123456789ABCDEF0h

at any rate.....
you can pass it as 2 dwords
that is what the assembler will do

the INVOKE above will generate code that looks something like this
push dword ptr qwMyVal+4
push dword ptr qwMyVal
call MyFunc


you can prototype the function with 2 dwords and achieve the same thing   :P

jj2007

Quote from: dedndave on September 07, 2013, 12:20:13 AM
however, i seem to recall ML v 6.14 and 6.15 having a problem with
qwMyVal QWORD 123456789ABCDEF0h

6.15 cannot handle MyO OWORD 123
Strangely enough, movups xmm0, OWORD PTR MyQ1 passes without problems with 6.15...

dedndave

ah yes - that's what it was - QWORD's are ok

ragdog

Thank you all for all this solution  :t

I found out the same as DaveĀ“s solution
with push

Quotepush  dword ptr[My64a+4]
push dword ptr[My64a]