I'm trying to write an inline string macro function (in MASM) that can work both with "invoke" calls and push commands. That is, depending on a parameter given to the macro, it should return either <ADDR inline_string> or <offset inline_string>.

For some reason, that is beyond me, the compiler refuses to let me do this, and I was hoping that anyone could tell me what it is that I don't understand. :(

Here is the simple macro:



ILStr MACRO Text, offset_mode
LOCAL lbl
LOCAL text_lbl
jmp lbl
text_lbl:
db Text,0
lbl:
IFNB offset_mode
EXITM <offset text_lbl>
ELSE
EXITM <ADDR text_lbl>
ENDIF
ENDM


The compiler says: "error A2051: text item required"


It works perfect if I remove the conditional return type though, making the macro look like this:



ILStr MACRO Text, offset_mode
LOCAL lbl
LOCAL text_lbl
jmp lbl
text_lbl:
db Text,0
lbl:
EXITM <offset text_lbl>
ENDM


I just don't get it. :( Any tips would be great.

Thanks!
Posted on 2002-12-15 10:22:00 by dELTA
ifnb requires square brackets around the param.
Posted on 2002-12-15 11:43:34 by japheth
Ah, thanks!
Posted on 2002-12-15 12:19:11 by dELTA
Hi dELTA,
Look at the included zip file. BYTER generates a inline ASCII string with a implicit label. LBYTER generates a inline ASCII string with a explicit label. Neither generates any jumps or instruction code. Ratch
Posted on 2002-12-16 16:21:15 by Ratch
Thanks for the example Ratch!

It was intentional by me to put the strings in the code segment though, but I know about this technique too.


Also, you write the following:

PUSH @ BYTER('THIS WILL PUSH THE ADDRESS OF THE STRING',0)


Won't this result in the following code?

PUSH offset offset <label_address>


Since you are already including the @ (which you have equ:d to "offset" earlier) in the macro return value, including it in the push instruction too only makes it double, doesn't it? Would the following work just as well?

PUSH BYTER('THIS WILL PUSH THE ADDRESS OF THE STRING',0)


According to my mind, that would result in the following code, wouldn't it (no "offset" duplication)?

PUSH offset <label_address>


Or have I misunderstood something?
Posted on 2002-12-16 19:43:25 by dELTA
dELTA,
You are correct. @ BYTER is superfluous. Fortunately MASM does not squawk on PUSH OFFSET OFFSET LAB1, or MOV EAX,OFFSET OFFSET LAB1 . The concise correct coding is PUSH BYTER('yah yah',0) or PUSH LBYTER(LAB1,'blah blah',0) and MOV EAX,@ LAB1, where the OFFSET directive MUST be included in the last example. Ratch
Posted on 2002-12-16 21:22:17 by Ratch