Re: NASM preprocessor



"Chuck Crayne" <ccrayne@xxxxxxxxxx> wrote in message
news:20080822150202.07be82c3@xxxxxxxxxxxxxxxxxx
On Fri, 22 Aug 2008 23:34:36 +0200
Herbert Kleebauer <klee@xxxxxxxxx> wrote:

Sadly the NASM macro system isn't powerful
enough to really "make" it a logical syntax.

There has been some discussion among the NASM developers about adding a
more powerful macro system. What features would you like to see?


One of the things I like is that the basic syntax of NASM's preprocessor
"mirrors" C's preprocessor syntax. So, if you don't adopt m4, which I have
no comment on, please keep the C style syntax.

%+1 allows you to add a condition code to an instruction, but %ifidn and
%elifidn only allow comparison with a single value. So, if you'd like a
body of code to be compiled only for condition codes be, ae, a, b, but not
others:

%ifidn %1,be
set%+1 al
%elifidn %1,ae
set%+1 al
%elifidn %1,a
set%+1 al
%elifidn %1,b
set%+1 al
%else
; other

E.g., I'd like a "%ifidn" that allowed multiple values to be passed to the
same section:

%ifidn %1, be, ae, a, b
; if the condition code in %1 is be, ae, a, or b, then do
set%+1 al
%else
; other

I haven't spent much time trying to figure out a way to convert an
indentifier from one register, say %2 is "eax" to say "al", except by %ifidn
and %elifidn... This effects instructions like setcc, movzx, movsx.
Instead of using %ifidn and %elifidn, it'd be nice if there was a function
to return the low 8-bit register al from 32-bit register eax or 16-bit
register ax, etc. E.g., you may have a condition code in %1, and a 32-bit
register in %2, say eax from a register allocator, but you need %2 to be al:

set%+1 %2 ; problem if not 8-bit... How to generate 8-bit from 16-bit or
32-bit easily without %ifidn and %elifidn for each register?

Or, maybe there just needs to be an example of how to do things like
this...?

I recall that there was a severe lack of ways to do string processing (which
HK mentioned also...) on identifier parameters.

I've also noticed heavy use of "%ifidn %elifidn %elifidn %elifidn ...
%else" which implies need of a "%switch" or "%case" or set of values for
"%ifidn" as suggested above...

Previously, I posted some other things I thought were weak:

Things I'd recommend are:
1) improve %substr to take a start and length
2) change %substr to work on identifier's, numbers, and strings
3) change %substr so it works in macro's or with concatenation %+
(i.e., don't assign to a variable)
4) add string functions:
a) C's strchr,strstr,strcpy (actually, I'd recommend strrchr...)
b) BASIC's left$,mid$,right$ and concatentation.
5) adding operators or unshrouding internal compiler logic for functions
used to build instructions. E.g., to convert a condition code to numbers,
logic to encode address modes, etc.

http://sourceforge.net/forum/message.php?msg_id=4335052


Rod Pemberton

.



Relevant Pages

  • Re: HLA History
    ... No, not like Motorola syntax. ... and RAX all overlap in the register space. ... Now granted, the x86 instruction set, as defined by Intel, ... > contain size, anyway...not that if in the mnemonics, then it doesn't need ...
    (alt.lang.asm)
  • Re: again, external symbols in hla
    ... The processor doesn't use any names, it is the Intel assembler syntax ... The encoding of the instruction has nothing to do with the symbolic ... chosen assembly syntax is a pure mess. ... of a register, then list is the symbolic name of a memory location. ...
    (alt.lang.asm)
  • Re: Betovs notation
    ... >> base on the same awful syntax with just a few improvements. ... and the destination is register 3. ... In the assembler source code ... the segment override should be written where it belongs: ...
    (alt.lang.asm)
  • Re: maybe a bit OT: EEPROMs and PCs
    ... We have a register set (let's use the names ... | content of memory location 4 into register 0. ... (not to mention that my keyboard got square brackets as prime keys). ... This seems to be reversed HLA/gcc syntax:) ...
    (alt.lang.asm)
  • Re: Betovs notation
    ... As a result any new version of the assembler ... > will recognize this instruction. ... OTOH, it's all just syntax. ... If you mapped the register numbers to their binary ...
    (alt.lang.asm)