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.
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
In DOS, those options are not by default, you can declare it as you want, but is a macro like any other macro.
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
and is that way with any other macros that I write, the linker always complains, what is the mistake I'm making
try names like DtaStatus, DtaBit, DtaFlag, DtaDir
even better - bDtaStatus, bDtaBit, bDtaFlag, wDtaDir
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
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?
no - see my previous post
you try to get the address of a macro argument
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?
my mistake - i guess arguments do not need a type
and - the assembler will complain when it tries to expand the macro
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.
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
this should also work
fmacro macro mbit,mstatus,mdata
mov bBit,mbit
mov bStatus,mstatus
mov wDir,offset mdata
endm
I was thinking in that Dave, I'll give it a try later thx.
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
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!
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:
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
Dave I change the name for the segment to "jklm", and I still get the same response from the assembler
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"?
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.
I'm so used to mplab, where writing macros is easy. EDITED :eusa_boohoo:
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?
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
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
simply looks like I can't write macros, that has happen to me in more than one program, the assembler is corrupted maybe.
finally I get the problem, a little detail :icon_redface:, thank you all for your kind help.
One must first declare the macro, then call the macro, not otherwise :biggrin:
the code in reply #15 should work for you
and, yes - macros are typically defined very near the beginning of source
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.,
f1 macro param
LOCAL loop1
loop1:
; do something
jmp loop1
endm
got it !! thanks.,