From: Betov on
"sevagK" <kahlinor(a)yahoo.com> ?crivait news:1142474343.554087.150300
@e56g2000cwe.googlegroups.com:


> Is this limit just for if..endif macros nesting or does the limit
> include nesting a combination of macros?

RosAsm has true local symbols. You cannot understand
what this is, but you can understand the form. It is:

"A0:", "A1:",... "A9:"
....
"Z0:", "Z1:",... "Z9:"

Any of these Symbols can be used anywhere, any number
of time, in any direction. So it is evident that there
is no practical limit to the nesting a combination of
different macros, and that a same Construct Macro is
limited to the number of nesting level given by the
Local Labels limit, from 0 to 9. Which is, also, a
"poisonned gift", that should evidently not be extended,
to not encourage the beginner to write badly organized
sources.


Betov.

< http://rosasm.org >



From: Betov on
Frank Kotler <fbkotler(a)comcast.net> ?crivait news:I4SdnXNWMYmnMYXZRVn-
hg(a)comcast.com:

> Why two "\\"s in "\\o//annabee" - oh, there aren't, anymore.

This was a Rock&Roll spider, but, when i joked Half about
cutting one arm of his cat to save her from the hen virus,
he chosed to send his spider to the surgeon, instead.


Betov.

< http://rosasm.org >

From: Betov on
Frank Kotler <fbkotler(a)comcast.net> ?crivait news:I4SdnXNWMYmnMYXZRVn-
hg(a)comcast.com:

> Why two "\\"s in "\\o//annabee" - oh, there aren't, anymore.

This was a Rock&Roll spider, but, when i joked Half about
cutting one arm of his cat to save her from the hen virus,
he chosed to send his spider to the surgeon, instead.


Betov.

< http://rosasm.org >

From: Frank Kotler on
o//annabee wrote:

....
> If you feel up to it. Can you explain this macro?

Most of it. I am not the Macro Guru. As Sevag says, it just pushes the
parameters...

> ; - - - - - - - - - - - - - - - - - - - - - - - - - -
>
> %macro Call 1-*

It's "%macro", not "%imacro", so it has to be spelled with an uppercase
'C'. It takes from 1 to any number of parameters.

> %define %%_j %1

The "%%_j" is a temporary variable - unique to this macro - that's used
to save the first parameter - the name of the function we're going to
call. No need to do this, one more "%rotate -1" after the "%rep" loop
would have put it back to %1...

> %rep %0-1

"%0" is the count of parameters to the macro, one is the name, the rest
are parameters to the function, so we push 'em.

> %rotate -1

Rotate the parameters "backwards" ("%rotate 1" would be forwards). So
the last parameter in our list is rotated into the "%1" (first
parameter) position.

> %ifstr %1

If it's a string...

> PushStr %1

Call another macro. I was *gonna* tell you that this put the string off
in the .data (or .rdata) section, with a "cryptic" (but unique) label on
it, then push that label. But I checked it out, and what it does is to
put the string in the middle of our code, and calls a label at the end
of it... thus pushing the address of the string as a "return address"
(that we never return to). Wish I hadn't looked!

Then we run down the registers one at a time - cause Nasm doesn't have a
"%ifreg" macro directive...

> %elifidni %1, eax
> push eax
> %elifidni %1, ebx
> push ebx
> %elifidni %1, ecx
> push ecx
> %elifidni %1, edx
> push edx
> %elifidni %1, esi
> push esi
> %elifidni %1, edi
> push edi
> %elifidni %1, ebp
> push ebp
> %elifidni %1, esp
> push esp

Whew!

> %elifid %1

If it's an identifier - variable or equate...

> %ifnum %1
> %if %1<040h
> push byte %1
> %else
> pushd %1

40h, eh? Fuckin' got me! The "pushd" is a macro: "push dword". He's
*got* a "pushb" - "push byte", dunno why he doesn't use it here.
Obviously, trying to make an "efficient" push - Nasm defaults to a dword
push, even if the operand fits in a signed byte, we've gotta say "push
byte" to get the short form. RosAsm does this automatically, and Nasm
does it if you use the "-O" switch. But why draw the line at 40h??? Mystery.

> %endif
> %else
> pushd %1

"push dword" again - as of 0.98, Nasm didn't "guess" that you wanted a
16-bit push in 16-bit code and a 32-bit push in 32-bit code, and made
you say "word" or "dword" every time - except, of course, registers,
where the size is specified - that's why the registers are "special
cased" above. Shortly thereafter, it was agreed that that was
ridiculous, and Nasm has defaulted to "push word" in 16-bit code and
"push dword" in 32-bit code. So almost all of this cruft is completely
unnecessary.

> %endif
> %elifnum %1
> %if %1<254
> push byte %1

A byte if it's under 254... oooookay. Nasm will warn (but generate
correct code) if we do "push byte 0FFh" it's a *signed* byte
instruction, so if you mean -1, say -1 (or ignore the bitchin'). So this
macro will generate warnings from 128 to 253, 254 and 255 are "push
dword". Whatever...

> %else
> pushd %1
> %endif
> %else
> pushd %1
> %endif
> %endrep
> %ifdef PEFILE
> apicall %%_j

This is a fancy call for "Nasm only" (no linker) files - in pemacs.inc:

call dword [%1 + IMAGEBASE + RVADIFF]

Unless I'm mistaken, this adjusts where it is in our binary file, to
where it is once it's loaded(?).

> %else
> call %%_j
> %endifs

Or else just a regular call (note that since it isn't spelled with
uppercase 'C', it doesn't go all recursive on us :)

I have no idea why the trailing 's' on "%endifs"...

> %endmacro

So there's a whole lot of complexity to this, just trying to get around
Nasm's defaults and generate the short form of the push... and cope with
"old Nasm"s insistance on "dword"...

The only thing "special" is the PushStr macro, so we can do:

Call MessageBoxA 0, "help, help", "Got help?", 0Ch

without having to declare the strings elsewhere and use the labels here.
Convenient... disassemblers won't love that data in the middle of the
code! I have in mind another way to do that - dunno if it would work in
these "binary PE" files...

The best thing about "user defined macros" is that anyone can write
their own macro file to do whatever they like. The worst thing about it
is that everybody does!

Best,
Frank
From: Betov on
Frank Kotler <fbkotler(a)comcast.net> ?crivait
news:ZPednXz3H_GB1ITZnZ2dnUVZ_vidnZ2d(a)comcast.com:

> The best thing about "user defined macros" is that anyone can write
> their own macro file to do whatever they like. The worst thing about it
> is that everybody does!

:)

Betov.

< http://rosasm.org >