Author Topic: Macros with masm 6.1  (Read 12838 times)

georg

  • Guest
Macros with masm 6.1
« 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.
               

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #1 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

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

georg

  • Guest
Re: Macros with masm 6.1
« Reply #2 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.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #3 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

georg

  • Guest
Re: Macros with masm 6.1
« Reply #4 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

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #5 on: September 18, 2013, 02:14:28 AM »
try names like DtaStatus, DtaBit, DtaFlag, DtaDir
even better - bDtaStatus, bDtaBit, bDtaFlag, wDtaDir

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #6 on: September 18, 2013, 02:18:03 AM »
have a look at masm32\macros\macros.asm for several examples

Code: [Select]
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

  • Guest
Re: Macros with masm 6.1
« Reply #7 on: September 18, 2013, 02:18:15 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

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #8 on: September 18, 2013, 02:20:28 AM »
no - see my previous post
you try to get the address of a macro argument

georg

  • Guest
Re: Macros with masm 6.1
« Reply #9 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?

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #10 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

georg

  • Guest
Re: Macros with masm 6.1
« Reply #11 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.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #12 on: September 18, 2013, 02:36:57 AM »
try this
Code: [Select]
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

Code: [Select]
        .DATA?

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

Code: [Select]
        .CODE

        fmacro 1,2,bFlag

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

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Macros with masm 6.1
« Reply #13 on: September 18, 2013, 02:40:01 AM »
this should also work
Code: [Select]
fmacro macro mbit,mstatus,mdata
                  mov bBit,mbit
                  mov bStatus,mstatus
                  mov wDir,offset mdata
            endm

georg

  • Guest
Re: Macros with masm 6.1
« Reply #14 on: September 18, 2013, 02:46:17 AM »
I was thinking in that Dave, I'll give it a try later thx.