SO_S MACRO String:VARARG
Local string
.data
string db String
align 4
.code
EXITM <offset string>
ENDM


Works fine when invoked from a code section. But changes the section type for anything that comes after the macro if invoked from data section.

Is there any way to check for current section type in masm? Or any other way to fix this (besides of writing two different macros) ?
Posted on 2006-07-08 22:09:46 by arafel
arafel,

SO_S MACRO String:VARARG
Local string
.data
string db String
align 4
.code
EXITM <offset string>
ENDM


TEXT MACRO P1:VARARG            ;inline code for BYTE string and implicit label
LOCAL L1
.DATA
L1 BYTE P1
.CODE
EXITM <OFFSET L1>
ENDM


    Looks remarkably like my TEXT MACRO doesn't it?  Anyway, I cannot figure out why you would want or need to call it from the .DATA section.  And why the DWORD ALIGN for the .DATA.  There might be some more character data following "string".  Ratch
Posted on 2006-07-09 00:09:27 by Ratch

?  ?  ? Looks remarkably like my TEXT MACRO doesn't it?? 

Are you implying that I stole it ?  :shock:

why you would want or need to call it from the .DATA section.


Pointer tables. It saves me from a lot of typing.

ptrs_tbl dd SO_S("some string1")
          dd SO_S("some string2")
          dd SO_S("some string3")
          .....

The above is much more convenient to me than manually defining and referencing the strings.

And why the DWORD ALIGN for the .DATA.  There might be some more character data following "string".


In general, you are right. However in my particular case dword alignment seemed to speed up things a bit at some specific functions, so I didn't bothered to remove it.
Posted on 2006-07-09 01:02:33 by arafel
arafel,

Are you implying that I stole it ?


    Not hardly.  Our MACROs are so basic and simple that they can hardly help but be similar.

ptrs_tbl dd SO_S("some string1")
          dd SO_S("some string2")
          dd SO_S("some string3")


    Interesting.  A table of addresses to strings.  But how are you going to prevent the strings from interspersing with the addresses?  I have encountered that problem.  To solve it, I needed one MACRO to generate the strings and save the addresses in automatically indexed global macro variables, and a second MACRO to generate the table of addresses from the global variables.  That guaranteed the strings and addresses were separate and linked.  Or maybe you can generate the strings in one data segment and the addresses in another.  Be interesting to try.  Ratch
Posted on 2006-07-09 01:44:06 by Ratch
I hadn't encountered any problems with addresses being interspersed, since with the above macro they were generated in data segment, while strings - in text segment. Two separate blocks...
Now that you mentioned it, I see that the solution I was after simply wouldn't work.


SOD MACRO String:VARARG

Local string

tmp_data_sec SEGMENT FLAT 'DATA'
string db String
tmp_data_sec ENDS

EXITM <offset string>
ENDM


+ merging the sections at link time seems to work fine. (Perhaps there is a way to merge them during the preprocessing? I have tried SEGMENT'S ALIAS directive, but without any success).
Posted on 2006-07-09 03:54:28 by arafel
Try this, code from BitRAKE iirc.


CTEXT MACRO y:VARARG
LOCAL sym

CONST segment
IFIDNI <y>,<>
sym db 0
ELSE
sym db y,0
ENDIF
CONST ends

EXITM <OFFSET sym>
ENDM

Posted on 2006-07-09 06:17:15 by f0dder
It worked perfectly. Thanks.
Posted on 2006-07-09 07:21:31 by arafel