NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: nobody on December 17, 2009, 05:55:18 PM

Title: General nasm doubt with %assign. (nasm v2.07
Post by: nobody on December 17, 2009, 05:55:18 PM
;;;;;;;;;;; test.asm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%assign i 5
%imacro if 3-*
%if %0 = 3
%push if
cmp     %1, %3
j%-2    near %$i
%else
%fatal  "if accepts 3 parameters."
%endif
%endmacro
%imacro else 0
%ifctx if
%repl else
jmp     near %$e
%$i:
%else
%fatal "Expected 'if' before 'else'"
%endif
%endmacro
%imacro endif 0
%ifctx if
%$i:
%pop
%elifctx else
%$e:
%pop
%else
%fatal "Expected 'if' before 'endif'"
%endif
%endmacro


segment .code USE32
..start:

mov eax,0
if eax,e,0
inc eax
endif
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

**NASM version 0.98.39:**

c:\nasm> nasmw -e test.asm

%line 31+1 test.asm


[segment .code USE32]
..start:

mov eax,0
cmp eax, 0
%line 37+0 test.asm
jne near ..@2.i
%line 38+1 test.asm
inc eax
..@2.i:
ret

**NASM version 2.07**

c:\nasm> nasmw -e test.asm

%line 31+1 test.asm


[segment .code USE32]
..start:

mov eax,0
cmp eax, 0
%line 37+0 test.asm
jne near 5
%line 38+1 test.asm
inc eax
5:
ret


Inside "if" and "endif" macros ..

%$i    is expanding to "5".

Just found this difference when using nagoa+.inc for win32 with nasm v2.07.


Thanks,

Mathi.
Title: Re: General nasm doubt with %assign. (nasm v2.07
Post by: Frank Kotler on January 24, 2010, 08:42:11 PM
Hi Mathi,

Sorry for the delayed reply. I don't know the answer - looks like a bug - and I haven't gotten around to looking into it. Have you tried it with the latest snapshot?

http://www.nasm.us

I'll check it out if I get a chance, but I'm even more "distracted" than usual, lately. Would "%xassign", help?

Best,
Frank

Title: Re: General nasm doubt with %assign. (nasm v2.07
Post by: Keith Kanios on January 24, 2010, 09:41:39 PM
Sorry for the delayed reply. I don't know the answer - looks like a bug - and I haven't gotten around to looking into it. Have you tried it with the latest snapshot?

Yeah, based on Mathi's explanation, it looks like %$i is, at least, evaluating i beforehand.