Hey ho and dum di dum.
I'm writing some macro code similar to the following:
this works... but obviously only once, after which there will be symbol
redefinition :(. I figured out how to make this work in nasm, by use
of %push and %pop ... but how would I go about this in masm?
I've browsed through the docs, but couldn't find anything.
I'm writing some macro code similar to the following:
BEGIN MACRO
db (offset @@end - offset @@start)
@@start:
ENDM
END MACRO
@@end:
ENDM
this works... but obviously only once, after which there will be symbol
redefinition :(. I figured out how to make this work in nasm, by use
of %push and %pop ... but how would I go about this in masm?
I've browsed through the docs, but couldn't find anything.
Afternoon, F0dder.
I think there may be symbol redefintion in re-used local labels anyway.
You could try setting the names yourself:
This way, you can nest and match up the Macros easily, plus it'll be easier to read after a few pints. (for those of you who don't know what a P-eye-nt is, it's a little bit larger than a Schooner).:grin:
Anyhoo, you can use it thus:
Hope this helps (is it what you needed, or was it actually something else that you required?)
Cheers,
Scronty
I think there may be symbol redefintion in re-used local labels anyway.
You could try setting the names yourself:
BEGINn MACRO Num:REQ
db (offset @@end&Num - offset @@start&Num)
@@start&Num:
ENDM
ENDn MACRO Num:REQ
@@end&Num:
ENDM
This way, you can nest and match up the Macros easily, plus it'll be easier to read after a few pints. (for those of you who don't know what a P-eye-nt is, it's a little bit larger than a Schooner).:grin:
Anyhoo, you can use it thus:
BEGINn 1
.
.
.
ENDn 1
BEGINn 2
.
BEGINn 3
.
ENDn 3
.
ENDn 2
Hope this helps (is it what you needed, or was it actually something else that you required?)
Cheers,
Scronty
@@NumBegin = 0
BEGIN MACRO
db (offset @@end&@@NumBegin - offset @@start&@@NumBegin)
@@start&@@NumBegin:
ENDM
END MACRO
@@end&@@NumBegin:
@@NumBegin=@@NumBegin+1
ENDM
Nesting Doesn't work though
BEGIN MACRO
db (offset @@end&@@NumBegin - offset @@start&@@NumBegin)
@@start&@@NumBegin:
ENDM
END MACRO
@@end&@@NumBegin:
@@NumBegin=@@NumBegin+1
ENDM
Nesting Doesn't work though
Thanks a lot, both of you! Especially Satrukaan's approach looks
very dandy -- I should have thought of such an approach myself.
Oh well, I should get more familiar with the masm macro language.
Nesting won't be a problem, btw. Thanks again!
very dandy -- I should have thought of such an approach myself.
Oh well, I should get more familiar with the masm macro language.
Nesting won't be a problem, btw. Thanks again!
Nice Scronty, and it's always good to include the pint factor. :)
f0dder, I'm not showing off or anything here, but check out this solution to your problem! :grin:
f0dder, I'm not showing off or anything here, but check out this solution to your problem! :grin:
.BEGIN MACRO
LOCAL myStart, myEnd
db offset myEnd - offset myStart
myStart LABEL BYTE
.END MACRO
myEnd LABEL BYTE
ENDM
ENDM
Oh, man I love me a macro! Hehehe... :alright:Brilliant, bitrake :). Seems like you're the macro guru around here, eh?
Nice and clean solution to the problem. Didn't know you could nest
macros, nor that nesting would work that way...
Satrukaan, your stuff didn't assemble as-is, but I believe I could
have made it working with the string concatenation stuff. Oh well,
bitrakes approach works and is pretty :].
Nice and clean solution to the problem. Didn't know you could nest
macros, nor that nesting would work that way...
Satrukaan, your stuff didn't assemble as-is, but I believe I could
have made it working with the string concatenation stuff. Oh well,
bitrakes approach works and is pretty :].
I look at macros as advanced cut-n-paste, and you don't have to loose the power of assembly - in fact it becomes more powerful. I don't think anybody really knows the MASM macro system - the documentation really isn't good and the syntax just isn't readable in complex macros. So far the biggest limitations in macros is the line length, and lack of more powerful symbolic types. You only have numbers and strings, but strings can refer to other labels which can be a number or string, and so on... This really makes it difficult to do some very simple things.
Oh, you will get an error if you try to nest the macro - good thing you didn't need it. :)
Oh, you will get an error if you try to nest the macro - good thing you didn't need it. :)
GlobalNumber = 0
.BEGIN MACRO
LOCAL myStart, myEnd
GlobalNumber = GlobalNumber + 1
db offset myEnd - offset myStart
myStart LABEL BYTE
@CatStr(<RealEnd>,<%GlobalNumber>) MACRO
myEnd LABEL BYTE
GlobalNumber = GlobalNumber - 1
ENDM
.END MACRO
@CatStr(<RealEnd>,<%GlobalNumber>)
ENDM
ENDM
I haven't found a way around the global number, yet. :)(Edit: Did a little fix to speed it up and reduce listing size.)
I can say Im impressed....
... any thoughts on a Tut?, Im currious to see what else is jumping around in your crazy yellow attic. :grin:
Good job anyways...
:alright:
NaN
... any thoughts on a Tut?, Im currious to see what else is jumping around in your crazy yellow attic. :grin:
Good job anyways...
:alright:
NaN
I changed it again...
NaN, really I'm just figuring things out myself. My big macro project right now is a lexical parser. This will ease language creation from within asm. You won't have to code the parser for a commandline unless you really want to. :) Plus, making a calculator will be a few lines of code. We're going to be able to write some very cool programs very quickly in asm. Well, that's the way I like to see it. :)
NaN, really I'm just figuring things out myself. My big macro project right now is a lexical parser. This will ease language creation from within asm. You won't have to code the parser for a commandline unless you really want to. :) Plus, making a calculator will be a few lines of code. We're going to be able to write some very cool programs very quickly in asm. Well, that's the way I like to see it. :)