Hello.

Just playing around with $INVOKE macro, I've encountered some troubles while using it in the same line as marked with a label. Seems it's the question of order MASM uses while compiling source code. Anyway - just take a look at the two pieces of code:


jmp @000
@000:
mov EBX,$INVOKE(Procedure)



jmp @000
@000: mov EBX,$INVOKE(Procedure)

The first one shall be compiled correctly:


jmp @000
@000:
call Procedure
mov EBX,EAX

However - the second one won't:


jmp @000
call Procedure ; this call will be omited
@000:
mov EBX,EAX

Since I'm used to place the code in the same line, which is marked with a label (well - depends, but usually I do), I've been trapped a couple of times looking for possible errors with debug output...

Any ideas of fixing the macro, so it could be used on the labeled line?

Regards, Mikael
Posted on 2003-09-29 19:12:00 by MikaelC
Thanks MikaelC,

This is a valid point but not one that i think is critical. Macros are to simplify things for your, not become a universal solution to everything in its class. You have to still think about how it will work in your source (which is more or less what your pointing out ;) ).

They are a great tool, not a crutch ;)
:alright:
NaN
Posted on 2003-09-29 19:49:01 by NaN
Originally posted by NaN
This is a valid point but not one that i think is critical. Macros are to simplify things for your, not become a universal solution to everything in its class.


Well - of course :) Seems that it's a good opportunity to place a comment for the labeled piece of code on the line with label and push the code to the next one :)

Mikael
Posted on 2003-09-30 03:49:05 by MikaelC
Are you suggesting this?



$Invoke MACRO args:REQ
[b] ; Dummy[/b]
invoke args
EXITM <eax>
ENDM


I havent tested this, but if my Macro theory is still with me, it should work... I never ever gave thought to useing comments in any macro for any other purpose than documentation...

:NaN:
Posted on 2003-09-30 21:04:56 by NaN
Nope, NaN, nope... Sorry - I was just kidding...

What I was thinking about (while joking) was changing:


@000: mov [Storage],$INVOKE(Procedure)

to:


@000: ; USE FREE SPACE TO COMMENT THE BLOCK OF CODE
mov [Storage],$INVOKE(Procedure)

But seriously... It's a kind of addiction. I don't like leaving a free space in code - and that's why I usually continue writing code in the same, labelled line.

Back to the topic - seems, that the first thing MASM do, is an association of label (as a location counter) with the "mov" instruction. INVOKE is resolved on the second place.

Cheers, Mikael
Posted on 2003-10-01 02:54:54 by MikaelC
Im surprised no one caught me on that above. It wont work for reasons you already hinted at.

The reason it fails is because the macro is programed to exit with 'EAX' in it place.

So your code:

@Foo: $INVOKE( GetDC, hDC )

Turns into:

invoke GetDC, hDC
@Foo: eax


Which is an obvious error. As well, having ";dummy" as a first line in the macro wont help since it will be placed befor the label "@Foo:" as follows:

;Dummy
invoke GetDC, hDC
@Foo: eax


In the end, your left with not much option but to avoid this scenario.
Regards,
:NaN:
Posted on 2003-10-01 16:01:28 by NaN
your left with not much option but to avoid this scenario

... or build a special kind of macro, used in labelled lines. But it's never been my intention...

Mikael
Posted on 2003-10-01 16:21:07 by MikaelC