Author Topic: nasm macro problems  (Read 16194 times)

nobody

  • Guest
nasm macro problems
« on: August 13, 2009, 03:33:05 PM »
Hi,

im trying to create a multiline macro that takes any number of parameters...
parameters look like  par1:size1, par2:sizre2.... (eg. a:dword, b:qword, c:byte) ... like in %local and %arg
My problem is how to separate the name from the size, i need to know the total size of all the parameters

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: nasm macro problems
« Reply #1 on: August 13, 2009, 07:26:05 PM »
Well, this ain't gonna be pretty! I *think* what you're going to have to do is find the ":", isolate the size with %substr, compare it with "byte" etc. to convert it to a number... and I guess add it into a "sum"... It *may* be that someone has already written a macro to do this, or similar, which would save you a lot of trouble. I don't know where to find such a thing (I'm not much of a macro user).

Suppose you had it... "my_thingy a:dword, b:qword, c:byte", and you added 'em up to get 13. Is this the number you want? Or does the "byte" parameter really need to be a dword? Are you going to want "movzx byte eax, [c]"? Or "movsx" perhaps? Are you going to want to pack multiple "byte" parameters into a dword? This could get hellishly complicated! Think carefully about what you want this macro to do, before you start writing it!

I don't know if it's still true, but some versions of Masm screw it up if you use a "byte" parameter in "invoke". Six (!) bytes on the stack! This suggests "it ain't easy!", to me...

Best,
Frank

nobody

  • Guest
Re: nasm macro problems
« Reply #2 on: August 13, 2009, 07:49:45 PM »
byte counts as 1... so its 13
i tried the thing with strings but nasm says %defstr dont exists (error: unknown preprocessor directive `%defstr') wich i need here...

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: nasm macro problems
« Reply #3 on: August 13, 2009, 09:29:24 PM »
"%defstr" is pretty new - I'm not sure which version, offhand. Grab the latest from:

http://www.nasm.us/

and I'm pretty sure you'll find it. Hope it helps!

Best,
Frank