The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: georg on September 18, 2013, 01:52:43 AM

Title: Macros with masm 6.1
Post by: georg on September 18, 2013, 01:52:43 AM
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.
               
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:04:10 AM
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 (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
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 02:09:16 AM
In DOS, those options are not by default, you can declare it as you want, but is a macro like any other macro.
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:12:16 AM
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
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 02:14:12 AM
and is that way with any other macros that I write, the linker always complains, what is the mistake I'm making
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:14:28 AM
try names like DtaStatus, DtaBit, DtaFlag, DtaDir
even better - bDtaStatus, bDtaBit, bDtaFlag, wDtaDir
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:18:03 AM
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
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 02:18:15 AM
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?
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:20:28 AM
no - see my previous post
you try to get the address of a macro argument
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 02:22:05 AM
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?
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:22:13 AM
my mistake - i guess arguments do not need a type

and - the assembler will complain when it tries to expand the macro
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 02:29:58 AM
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.
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:36:57 AM
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
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:40:01 AM
this should also work
fmacro macro mbit,mstatus,mdata
                  mov bBit,mbit
                  mov bStatus,mstatus
                  mov wDir,offset mdata
            endm
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 02:46:17 AM
I was thinking in that Dave, I'll give it a try later thx.
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:49:30 AM
this seems to build ok
        .MODEL  Small
        .STACK  2048
        .DOSSEG
        .386
        OPTION  CaseMap:None

;####################################################################################

fmacro  macro mbit,mstatus,mdata
        mov     bBit,mbit
        mov     bStatus,mstatus
        mov     wDir,offset mdata
    endm

;####################################################################################

;        .DATA

;************************************************************************************

        .DATA?

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

;####################################################################################

        .CODE

;************************************************************************************

_main   PROC    FAR

        fmacro  1,2,bFlag

        mov     ax,4C00h
        int     21h

_main   ENDP

;####################################################################################

        END     _main


so, it would appear it didn't like one or more of the names, "status", "bit", "flag", "dir"
also - the name "DTA" stands for "Data Transfer Area"
probably not a public symbol - just wanted you to know   :P
Title: Re: Macros with masm 6.1
Post by: qWord on September 18, 2013, 02:50:29 AM
the macro from the OP look OK - the problem must be caused by the call or it's arguments.
Macro arguments can have any name, because they are local (but of course not MASM's reserved words).
You might post the source, or a reduce form of it. The corresponding output from the build console might also be helpful.

BTW: the error message come from the assembler and not the linker!
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 02:54:15 AM
qWord,
in his data segment, he has labels, "status", "bit", "flag", "dir"
it was probably choking on one of those - "bit" is most likely
but, none of them are good names   :biggrin:
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 05:14:03 AM
I'm going to try to change the name of the arguments, maybe is the cause of the problem, (the assembler should point at the wrong code though not try the macro like a black box) the masm 6.1 have a command line option to enable macros?, or disable I think not, but just in case. this is the message:

error A2008: syntax error fmacro
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 05:17:16 AM
Dave I change the name for the segment to "jklm", and I still get the same response from the assembler
Title: Re: Macros with masm 6.1
Post by: japheth on September 18, 2013, 05:23:58 AM
Quote from: georg on September 18, 2013, 05:14:03 AM
error A2008: syntax error fmacro

This is a very strong indication that the assembler doesn't know "fmacro".

Perhaps you didn't show us the full source code? What's between the definition of fmacro and the macro "invokation"?

Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 05:31:15 AM
Quote from: japheth on September 18, 2013, 05:23:58 AM
Quote from: georg on September 18, 2013, 05:14:03 AM
error A2008: syntax error fmacro

This is a very strong indication that the assembler doesn't know "fmacro".



hi: japheth
that's exactly what I mean, and is the only error, if I copy paste the macro code, I don't get the error.
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 05:43:08 AM
I'm so used to mplab, where writing macros is easy. EDITED  :eusa_boohoo:
Title: Re: Macros with masm 6.1
Post by: qWord on September 18, 2013, 05:54:17 AM
Quote from: georg on September 18, 2013, 05:31:15 AMif I copy paste the macro code, I don't get the error.
How should we interpret that?
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 06:02:50 AM
Hi: qWord

jklm segment public 'data'
cbit    byte  ?
cstatus byte ?
cflag byte ?
cdir word ?
jklm ends

fmacro  macro fbit,fstatus,fflag
              mov cbit,fbit
              mov cstatus,fstatus
              mov cdir, offset fflag
            endm
inst segment readonly public 'code'
            assume cs:inst, ds:jklm
main   proc
          fmacro 1h,2h,cflag
          mov  ax,4c00h
          int    21h
main   endp
inst ends
          end

I simply copy the macro code:


jklm segment public 'data'
cbit    byte  ?
cstatus byte ?
cflag byte ?
cdir word ?
jklm ends

inst segment readonly public 'code'
            assume cs:inst, ds:jklm
main   proc
;         fmacro 1h,2h,cflag
          mov cbit,1h
          mov cstatus,2h
          mov cdir, offset cflag
          mov  ax,4c00h
          int    21h
main   endp
inst ends
          end

I could have made a mistake, but is only an example.

EDITED
Title: Re: Macros with masm 6.1
Post by: qWord on September 18, 2013, 06:17:53 AM
please stop editing your post!
I was able to assemble the code you did supply - there was only a spelling error: dFlag instead of bFlag.

   .MODEL  Small
        .STACK  2048
        .DOSSEG
        .386
        OPTION  CaseMap:None

;####################################################################################

fmacro  macro mbit,mstatus,mdata
        mov     bBit,mbit
        mov     bStatus,mstatus
        mov     wDir,offset mdata
    endm

;####################################################################################

;        .DATA

;************************************************************************************

        .DATA?

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

;####################################################################################

        .CODE

;************************************************************************************

_main   PROC    FAR
       fmacro 1h,2h,bFlag

;////////////////////////////////////////
        mov     ax,4C00h
        int     21h

_main   ENDP
            END _main
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 06:28:23 AM
simply looks like I can't write macros, that has happen to me in more than one program, the assembler is corrupted maybe.
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 08:18:48 AM
finally I get the problem, a little detail :icon_redface:, thank you all for your kind help.
Title: Re: Macros with masm 6.1
Post by: georg on September 18, 2013, 08:20:59 AM
One must first declare the macro, then call the macro, not otherwise  :biggrin:
Title: Re: Macros with masm 6.1
Post by: dedndave on September 18, 2013, 08:24:26 AM
the code in reply #15 should work for you
and, yes - macros are typically defined very near the beginning of source
Title: Re: Macros with masm 6.1
Post by: ggmasm32 on September 17, 2015, 05:09:49 AM
i have a question regarding the macro labelling.
I do remember when you declare label inside macro and call it multiple times, assembler will complain for multiple label with same name:

f1 macro param
loop1:
     ; do something
     jmp loop1
     endm

Now from main.asm call it twice and you get error


f1 param1
f1 param2

There was a special directive that generates different label suffix or prefix for each macro call, i cant recall, does someone remember?
Thanks.,
Title: Re: Macros with masm 6.1
Post by: jj2007 on September 17, 2015, 05:22:18 AM
f1 macro param
LOCAL loop1
loop1:
     ; do something
     jmp loop1
     endm
Title: Re: Macros with masm 6.1
Post by: ggmasm32 on September 17, 2015, 06:43:43 AM
got it !! thanks.,