Hi there...

I wrote this buggy macro ...

GetD MACRO target:=<DSec>, datbase:=<0>
mov eax, [esp+&datbase&]
IF target NE <DSec>
add eax, (&target&-DSec)

... which should generate those instructions ...

mov eax, [esp+0] [b](1)[/b]

-- or --

mov eax, [esp+8]
add eax, dwList-DSec [b](2)[/b]

... when it is called like this:

[b](1)[/b] GetD
[b](2)[/b] GetD dwList, 8

But it won't work at all... DSec is a proc, defined after the MACRO
and also after the location where the macro is called ... I tried to put a
"DSec PROTO" into the header. Didn't help.

Furthermore, dwList is defined as a simple doubleword inside DSec

Nevertheless, MASM gives me a syntax error in the line with the IF expression.
Also, would I need to use VARARG to make it work without any arguments?

Thanks for your valuable help! :)

aweX <-
Posted on 2003-02-20 12:14:49 by aweX
GetD MACRO target:=<DSec>, datbase:=<0>

mov eax, [esp + datbase]

[COLOR=purple]IFDIFI[/COLOR] target,<DSec>
add eax, target - DSec
You must do a string comparison, otherwise comparison is numeric.
Personally, I like this solution:
GetD MACRO target:=<>, datbase:=<0>

mov eax, [esp + datbase]

IFNB <target>
add eax, target - DSec
Posted on 2003-02-20 20:18:29 by bitRAKE
If DSec is a procedure, it is not fixed to a certain position in memory and thus MASM can't evaluate 'target - DSec' at assembly time. 'target + DSec' would work.
Posted on 2003-02-21 00:31:16 by gliptic
@bitRAKE: Thank you, it works wonderful now!
Posted on 2003-02-21 09:07:13 by aweX