News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Macros with masm 6.1

Started by georg, September 18, 2013, 01:52:43 AM

Previous topic - Next topic

georg

Hello people, I'm using masm 6.1, and I have problems with macros, and I don't know why to set an example;

true = 0
false = 0ffh

dta segment public 'data'
status byte ?
bit byte ?
flag byte ?
dir word ?
dta ends

fmacro macro mbit,mstatus,mdata
                  mov al,mbit
                  mov bit,al
                  mov al,mstatus
                  mov status,al
                  mov ax,offset mdata
                  mov dir,ax
            endm

------------------------------------------
              fmacro 2h,true,flag
              call     writeBit

, the linker complains, and it says: 'fmacro' syntax error, why? :exclaim:

EDITED SEVERAL TIMES.
               

dedndave

first, FALSE = 0 and TRUE = 1, well - in windows, at least
in the "real" world, TRUE = not FALSE, which would also be -1, but windows uses 1 for TRUE
FALSE and TRUE (upper case) are already defined for you in windows.inc

anyways...
the syntax error is probably in the first line

there are different types of arguments that a macro can have
you might have a variable number of arguments, required arguments, and so on
have a look at masm32\macros\macros.asm for several examples
and, of course, the manual

http://people.sju.edu/~ggrevera/arch/references/MASM61PROGUIDE.pdf

also - i seem to recall seeing "mbit" used somewhere
you might use more unique/descriptive names

georg

In DOS, those options are not by default, you can declare it as you want, but is a macro like any other macro.

dedndave

status, bit, flag, dir
those are pretty common names
i would be a little surprised if there wasn't a conflict somewhere
"bit" - i think that's a masm reserved word

georg

and is that way with any other macros that I write, the linker always complains, what is the mistake I'm making

dedndave

try names like DtaStatus, DtaBit, DtaFlag, DtaDir
even better - bDtaStatus, bDtaBit, bDtaFlag, wDtaDir

dedndave

have a look at masm32\macros\macros.asm for several examples

fmacro macro mbit:REQ,mstatus:REQ,mdata:REQ
                  mov al,mbit
                  mov bDtaBit,al
                  mov al,mstatus
                  mov bDtaStatus,al
                  mov ax,offset mdata           ;this line definately won't work
                  mov wDtaDir,ax
            endm

georg

Quote from: dedndave on September 18, 2013, 02:14:28 AM
try names like DtaStatus, DtaBit, DtaFlag, DtaDir
even better - bDtaStatus, bDtaBit, bDtaFlag, wDtaDir

hey Dave, but you say thet the syntax in the code section is right, right?

dedndave

no - see my previous post
you try to get the address of a macro argument

georg

I agree but, shouldn't the linker complain in the line I'm making the mistake inside the code, instead of saying that the name of the macro is a syntax error?

dedndave

my mistake - i guess arguments do not need a type

and - the assembler will complain when it tries to expand the macro

georg

when I copy and paste the macro code, in the code the program works fine, so it makes me wonder. Yes in 16 masm you don't need to specify the type of parameters, to the macro.

dedndave

try this
fmacro macro mbit,mstatus,mdata
                  mov al,mbit
                  mov bBit,al
                  mov al,mstatus
                  mov bStatus,al
                  mov ax,offset mdata
                  mov wDir,ax
            endm


        .DATA?

bStatus db ?
bBit    db ?
bFlag   db ?
wDir    dw ?


        .CODE

        fmacro 1,2,bFlag


because you are passing a label name that has an address, "offset mdata" does work

dedndave

this should also work
fmacro macro mbit,mstatus,mdata
                  mov bBit,mbit
                  mov bStatus,mstatus
                  mov wDir,offset mdata
            endm

georg

I was thinking in that Dave, I'll give it a try later thx.