NASM and Macros...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
darklife

NASM and Macros...

Post by darklife »

Oh how I love NASM :D
Is there any GOOD information on creating macros for NASM since imho macros make assembly programming much easier. I found a few examples in the NASMIDE help files for using an if|else|endif within NASM along with some other useful routines to make it more high level orientated. I know I could use an external parser but universal source code (NASM ;D) is always better than forcing others to use some third party tool to understand your source.
It would be cool to create a good include file to allow coders to use high level like code within NASM using nothing more than macros.
Ideas are welcome.
Tim

Re:NASM and Macros...

Post by Tim »

Did you read NASMDOC.TXT, the NASM documentation? That should have everything you need.

Personally I've been using gas recently. It uses the C preprocessor, which is quite powerful.
darklife

Re:NASM and Macros...

Post by darklife »

Well..... no :-[
I didn't get any docs with my NASM distro for DOS or Linux. I figured there was none. I'll do a google. (I should have done first)
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:NASM and Macros...

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:23 pm, edited 1 time in total.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:NASM and Macros...

Post by Solar »

darklife wrote: I know I could use an external parser but universal source code (NASM ;D) is always better than forcing others to use some third party tool to understand your source.
Except for those who consider NASM to be a third-party tool. ;-)

But that's the downside with assemblers. They pretty much *are* proprietary, each and every one of them. I opted for gas simply because a) it came with gcc, and b) it integrates so well with gcc. ;-)
Every good solution is obvious once you've found it.
Tim

Re:NASM and Macros...

Post by Tim »

That's exactly why I'm switching to gas. It means people who want to compile Mobius don't have to download Nasm separately, since gas comes with gcc. It also means that I get full debug information for my assembly code.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:NASM and Macros...

Post by Pype.Clicker »

i've not been much in details of GAS's macro processor, but i have to say NASM's one is *very* powerful ... So powerful that i used to use it even for processing simple command languages of my own ...

as for "downloading nasm too", most Linux distro now have NASM provided and, well, it's just *one* binary file (well, 2 if you want ndisasm aswell) to have in your path ... that's hardly complicated to install ;D

Considering problems with GCC3.x vs GCC2.9x vs DjGPP vs Cygwin, for instance, nasm is damn easy to install ...
Schol-R-LEA

Re:NASM and Macros...

Post by Schol-R-LEA »

Pype.Clicker wrote: i've not been much in details of GAS's macro processor
Actually, you already have used it before quite a bit.

Just not with gas.

The default macro preprocessor for gas is cpp, and it works pretty much the same way it does with C source code. There are more sophisticated macro processors one can use, such as M4, but cpp is the most popular because of it's familiarity.

I have found cpp to be very flexible; around 1995 or so, I had a CGI script that would run cpp over our HTML source before serving it; the code was full of #ifdefs to select the appropriate browser-specific code. It was an ugly hack, but it worked better than most of the solutions available at the time.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:NASM and Macros...

Post by df »

i spent the last weekend trying to use wasm and was having a shitload of trouble! hahah too used to nasm and its no rules apply approach...

i couldnt go to gas, its a POS imo.

what I am trying to do is move away from plain asm files, but for a couple of things like BIOS32 calls, I cant get around them...

right now I am writing a win32 coff object linker to support my own format :-X

i dont think its much to ask for people to have nasm.. certainly if they are going to build an os for testing/playing with...
-- Stu --
darklife

Re:NASM and Macros...

Post by darklife »

df wrote: i dont think its much to ask for people to have nasm.. certainly if they are going to build an os for testing/playing with...
Who doesn't have a copy of NASM? ;D
I find that mmmMASM is a pain, but it does('nt :P) work when needed. Most assemblers seem to be based on NASM syntax.
Tim

Re:NASM and Macros...

Post by Tim »

Most PC assemblers, including NASM, are based on the original Intel syntax. NASM and TASM both show most similarity to MASM.

The assemblers for more platforms are based on AT&T syntax, since they originally stem from that assembler.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:NASM and Macros...

Post by Pype.Clicker »

Schol-R-LEA wrote:
Actually, you already have used it before quite a bit.
(...)I have found cpp to be very flexible (...)
Well, compared to nasm's preprocessor, CPP is flexible like Effeil's tower. Nasm's preprocessor has multi-line macros that can define their own namespace and you have a /stack/ of macro variables, which you can manipulate to have nested constructions.

It's quite easy, for instance, to create three macro-definitions begin, end and use so that use must always be between begin and end and it's also pretty simple to make use's translation dependent on a parameter of begin even if you allow nested begin/end blocks ...

I challenge you to achieve this cleanly with #ifdefs ...
Schol-R-LEA

Re:NASM and Macros...

Post by Schol-R-LEA »

I wouldn't even consider taking that challenge; multiline macros in cpp are a nasty kludge at best.

I wasn't talking about its effectiveness as a macro preprocessor, but as a tool that can be applied to a variety of situations aside from the one it was designed for. The main advantage of cpp is that it is simple and low-overhead; it works very nicely as a filter, and the syntax is simple enough that it can be used with many different languages and markups.

As a macro preprocessor, cpp is stone knives and bear skins, and was even in 1970; but for the sort of situation I'm talking about, that's more than enough.

OTOH, if it's powerful macros you want, some of the other macro preprocessors like m4 make NASM's macros look skimpy. For that matter, MASM's macro facility is quite powerful, though hideously ugly.

Actually, the real heydey of macro preprocessors was in the early 1970s. For example, there was a notorious Macro Assembler implementation of SNOBOL4 - that is, the SNOBOL language was implemented as a set of preprocessor macros, and SNOBOL programs would be just run through the macro assembler with the necessary macro libraries. The Common LISP macro facility is a relic of that era, and even it isn't as powerful as many.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:NASM and Macros...

Post by Solar »

Erm...

While you can use cpp with both gcc and gas - which is really useful for interfacing C and ASM without redundant / scattered definitions e.g. of constants - gas has macro features in its own right.

http://www.gnu.org/manual/gas-2.9.1/htm ... tml#SEC109
Every good solution is obvious once you've found it.
Schol-R-LEA

Re:NASM and Macros...

Post by Schol-R-LEA »

Thanks, I'd missed that somehow.
Post Reply