Hello,

I wanted a macro for a push QWORD replacement so I wrote this :

(puqw = "push QuadWord")



puqw MACRO value:REQ
push dword ptr[value]
push dword ptr[value+4]
endm



It works, but how could I do a "type checking" to know if the parameter (value) supplied to the macro is trully a QW ?

Is it possible ?

Thank you very much.

Regards, Neitsa.
Posted on 2004-11-13 00:17:21 by Neitsa
Use OPATTR operator to check if the parameter is really a memory expression. I use one of Four-F's nice macros:
$IsMem MACRO op:REQ

IF (OPATTR (op)) AND 00000010y
;; is a memory variable or has a relocatable data label
EXITM <1> ; true
ELSE
EXITM <0> ; false
ENDIF
ENDM


To check the QWORD, use TYPE operator. I modify one of Four-F's macros:
$IsQword MACRO op:REQ 

IF (TYPE (op)) EQ 8
EXITM <1>
ELSE
EXITM <0>
ENDIF
ENDM


I think this will work.
Posted on 2004-11-13 05:38:37 by MazeGen
$IsQword MACRO op:REQ 

IF (TYPE (op)) EQ TYPE QWORD
EXITM <1>
ELSE
EXITM <0>
ENDIF
ENDM



POINT & REAL8 will match the original which are not qwords.
Posted on 2004-11-13 06:30:09 by gfalen
I don't know RECT - where is it defined?
About REAL8, will it cause any problem?
Posted on 2004-11-13 06:45:53 by MazeGen
Actually I should have said POINT not RECT. A POINT is a windows struct of 2 dwords (8 bytes). The TYPE operator knows the difference between POINT, QWORD, REAL8 although they are all 8 bytes. But you have to use TYPE the way I showed you.

The way TYPE was used in the first macro retains only the SIZE information and it will match any struct of 8 bytes.
Posted on 2004-11-13 07:58:26 by gfalen
Hello,

That's great! I wish to thank you for your replies. I've got a little problem (I'm not confident with Macros). I don't know how to combine each macros into 1, or if I could call a macro inside a macro.

I've tried this:



puqw MACRO value:REQ
IF (OPATTR (value)) AND 00000010y
IF (TYPE (op)) EQ TYPE QWORD
push dword ptr[value]
push dword ptr[value+4]
ELSE
EXITM <0>
ENDIF
ELSE
EXITM <0>
ENDIF
ENDM


but it doesn't work. output => error A2008: syntax error : puqw

If I try this:



puqw MACRO value:REQ
$IsQword value
push dword ptr[value]
push dword ptr[value+4]
ENDM


$IsQword MACRO op:REQ
IF (TYPE (op)) EQ TYPE QWORD
EXITM <1>
ELSE
EXITM <0>
ENDIF
ENDM



It won't work also => error A2008: syntax error : $IsQword


The macro is called like this:



.data
Ten QWORD 10d

.code

puqw Ten



Sorry for this question...I think that Macros are not easy to understand. BTW I'll continue to search.

Thank you very much. Regards, Neitsa.
puqw Ten
Posted on 2004-11-13 08:37:02 by Neitsa
Actually I should have said POINT not RECT. A POINT is a windows struct of 2 dwords (8 bytes). The TYPE operator knows the difference between POINT, QWORD, REAL8 although they are all 8 bytes. But you have to use TYPE the way I showed you.

The way TYPE was used in the first macro retains only the SIZE information and it will match any struct of 8 bytes.

Sounds interesting, but AFAIK "TYPE QWORD" returns only the size of QWORD, i.e. 8, no additional informations. Am I wrong?

Anyway, I assume an user of this macro knows what he pushes, and maybe he want to push also POINT or REAL8, why not?
Posted on 2004-11-13 08:39:58 by MazeGen
2 Neitsa:
You don't need to combine the macros, just call them:
puqw MACRO value:REQ

IFE $IsMem (value)
ECHO puqw macro error: use a memory variable, man...
.ERR ;; raise error
EXITM ;; prevent additional errors, exit macro
ENDIF
IFE $IsQword (value)
ECHO puqw macro error: use an qword, man...
.ERR
EXITM
ENDIF
push dword ptr[value]
push dword ptr[value+4]
endm
Posted on 2004-11-13 09:09:04 by MazeGen
MazeGen: The TYPE operator actually has more info than just the size but you have to use it correctly.

if (type byte) eq (type sbyte)

or al, 1
endif
if (type byte) eq (type byte)
or al, 1
endif

C if (type byte) eq (type sbyte)
C endif
C if (type byte) eq (type byte)
0000039C 0C 01 C or al, 1
C endif
Posted on 2004-11-13 10:57:57 by gfalen
gfalen: thanks, that's new for me :shock: Hmm, I could try it myself first...
Posted on 2004-11-13 11:11:19 by MazeGen
Hello,

:!: :!: :-D

I wish to thank you both MazeGen and Gfalen ! It works great !

Damn, Macros are very powerfull but not very easy to write. I'll spend more time on studying them.

Thanks again !

Regards, Neitsa.
Posted on 2004-11-13 17:47:37 by Neitsa