Author Topic: multiline macros with multiple parameters  (Read 14335 times)

x-trange

  • Guest
multiline macros with multiple parameters
« on: June 18, 2005, 12:43:13 AM »
hello, can anyone help on this one real fast?

i'm trying to create a multiline macro that uses 5 paramaters and uses labels defined outside of the macro. i also don't know how to run a macro with more than 1 parameter. i tried reading the nasm manual but i jus't can't figure it. this is the code i'm writing:

;macro for writing on the screen in 640x480 mode
;1- # of chars   2- line   3- column
;4- color   5- var where text is stored
%macro writemsg 5
          mov       cx,%1
          mov       bx,0
          mov       dh,%2
          mov       dl,%3
          mov       byte [color],%4
     lmsg:
          call      cursor
          mov       al,[bx+%5]
          call      character
          inc       bx
          inc       dl
          loop      lmsg

mov       ah,08h
          int       21h
          mov       ah,0
          mov       al,[last_mode]
          int       10h
%endmacro

i'm tried to run this macro like this:
writemsg 23 1 27 white graphtitle
and like this
writemsg 23,1,27,white,graphtitle

graphtitle, last_mode and and color are defined on the data segment. cursor and character are labels defined at the end of the code segment, and they have a ret at their ends.

our teacher told us to run nams like this:
nasm16 -f obj -o %1.obj -l %1.lst filename.asm

and then link it with freelink

the error i'm getting is when running nasm on the file:
parser : instruction expected

this happens at the line where i try to run the macro.

i used this code before, but not as a macro, and it worked just fine. can anyone give me some help? i'm lost here. maybe i can post the whole code if needed. thanks a lot in advance.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: multiline macros with multiple parameters
« Reply #1 on: June 18, 2005, 03:56:38 AM »
Hi George,

...
> ;macro for writing on the screen in 640x480 mode
> ;1- # of chars   2- line   3- column
> ;4- color   5- var where text is stored
> %macro writemsg 5
>           mov       cx,%1
>           mov       bx,0
>           mov       dh,%2
>           mov       dl,%3
>           mov       byte [color],%4
>      lmsg:
>           call      cursor
>           mov       al,[bx+%5]
>           call      character
>           inc       bx
>           inc       dl
>           loop      lmsg
>
>           mov       ah,08h
>           int       21h
>           mov       ah,0
>           mov       al,[last_mode]
>           int       10h
> %endmacro
>
> i'm tried to run this macro like this:
> writemsg 23 1 27 white graphtitle
> and like this
> writemsg 23,1,27,white,graphtitle

The second way is correct - it won't work without the commas.

> graphtitle, last_mode and and color are defined on the data segment. cursor
> and character are labels defined at the end of the code segment, and they have
> a ret at their ends.

That all sounds okay.

> our teacher told us to run nams like this:
> nasm16 -f obj -o %1.obj -l %1.lst filename.asm

Why in the world are you using nasm16??? Because your teacher told you to, I suppose... Why in the world does your teacher... Never mind, when you finish the course, get a better build of Nasm (*any* of 'em!). Nasm16 is for 286s!

> and then link it with freelink

I'm not familiar with that. I assume it does what it's supposed to. Not part of your problem, in any case.

> the error i'm getting is when running nasm on the file:
> parser : instruction expected
>
> this happens at the line where i try to run the macro.

With the invocation without the commas, I'd expect that, but with the commas... I dunno. Your macro, and the invocation *with* the commas look okay to me... not that I'm any expert on Nasm's macros...

> i used this code before, but not as a macro, and it worked just fine.

I don't see why you want to do this as a macro, but it oughtta work!

> can anyone
> give me some help? i'm lost here. maybe i can post the whole code if needed.
> thanks a lot in advance.

I don't see where the problem is, I'm afraid. Maybe someone else can spot it. If you can't figure it out, post the whole code - hard to actually try out "partial" code... and I suspect the problem is something very minor... It basically looks okay to me.

Best,
Frank

x-trange

  • Guest
Re: multiline macros with multiple parameters
« Reply #2 on: June 18, 2005, 07:00:02 AM »
thanks Frank,

we use nasm16 because the computers available to us are 286-486. it's just for learning some assembly, the good computers are used to run some serious matlab code on other labs, so we don't hog resources and if we write to the disc accidently, there's no big deal.

i'm trying to write this as a macro because i will use this a lot, with lots of different parameters, and to learn macros, of course.

well, as i tried using nasm32, i moved the code around a bit and it worked. i wasn't paying attention to the fact that i was trying to run a macro before i defined it!

thanks for your support.