NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Klod on August 31, 2010, 03:07:21 AM
-
This macro works fine with version 8 but not with nasm-2.09rc4
%imacro uses 1-*.nolist
%ifctx proc
%push uses
%assign %$j 0
%rep %0
%assign %$j %$j+1
%xdefine %$reg_%$j %1
push dword %1
%rotate 1
%endrep
%elifctx uses
%rep %0
%assign %$j %$j+1
%xdefine %$reg_%$j %1
push dword %1
%rotate 1
%endrep
%else
%error "'USES' must be used inside 'PROC/ENDPROC'"
%endif
%endmacro
It produces error:`%xdefine' expects a macro identifier
Isn't %define and %xdefine the ways to define single line macros?
regards
Klod
-
Try 2.09, Klod - seems to work for me. Temporary glitch in 2.09rc4?
Best,
Frank
-
Whoops, I spoke too soon. If I actually "%push proc", I do get that message. Doing:
%xdefine %$reg_%+%$j %1
seems to work...
O'course, Keith is, how's the manual put it? "improve it out of all recognition" to the preprocessor, so glitches could crop up, as it develops. I think "backward compatibility" is intended - except for that ill-advised "look in outer contexts for context-specific variables" misfeature. 2.09 is supposed to warn, if that change is about to bite ya. :)
Best,
Frank
-
yeah, please try 2.09 and if it fail -- please post the caller code not only macro itself, thanks.
-
I did compile with 2.09 and I do get the same error. I had compiled with both 2.09rc4 and 2.09rc7 with the same error.
I'm including here a copy of the program with the uses macro commented out and substituted with push/pop registers, it compiles and runs fine. This macro by the way I have adopted from one of Bryant Keller's post from a few years ago as are some of the other macros used in this example
See attached project
I compile with \nasm\bin\gorc,,, \nasm\bin\NASM -f win32,,, \nasm\bin\golink @\nasm\bin\GFL.txt /entry Start
The errors I get:
\nasm\bin\NASM -f win32 "C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm"
C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm:82: error: `%xdefine' expects a macro identifier
C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm:106: error: comma, colon or end of line expected
C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm:106: error: comma, colon or end of line expected
This is Line 82: uses ebx,edi
This is line 106: ENDP
And this is the offending statement: %xdefine %$reg_%$j %1
I wonder if this topic is not related??
http://forum.nasm.us/index.php?topic=863.0 (ftp://http://forum.nasm.us/index.php?topic=863.0)
Possibly not the correct context?
Regards
Klod
-
See attached project
The first thing I see is...
%include '\nasm\inc\nasmmacros.asm'
%include '\nasm\inc\windows.inc'
... in which please provide those exact files as you have them, as a reply to this thread.
-
I don't think this is a "context" issue. I think it's a "token pasting"(?) issue. Both "$reg_ " and "%$j" are okay (I think) - both defined in this context. At one time (under some circumstances, at least) you could just jam 'em together:
%xdefine %$reg_%$j %1
"%+" has existed for some time as the "prefered"(?) way to do this...
%xdefine %$reg_%+%$j %1
Apparently, now you "have" to do it that way. I don't know if this is a "bug" or not. Since "%+" exists, I just figure "that's the way you're supposed to do it"... but it *is* a change...
At least, that works in my "test" code. Can you confirm whether that works or not in its "native habitat", Klod?
How "should" 2.10 do it, is the question...
Best,
Frank
-
I tend to use Macro Indirection (http://www.nasm.us/doc/nasmdoc4.html#section-4.1.3) for complex cases.
-
Thank you all for your replies.
Frank, I think you are correct. I had tried %+ before and I still got compile errors and had therefore discounted this possibility. I have played around a bit and this is what I have come up.
Your suggestion %xdefine %$reg_%+%$j %1 solves the define issue.
BasicWindow.asm:82: warning: 1 ebx1
BasicWindow.asm:82: warning: 2 edi2
BasicWindow.asm:82: warning: 3 esi3
However there is one more issue:
This is in the ENDP macro, when restoring the registers
BasicWindow.asm:107: error: comma, colon or end of line expected
This line: pop dword %$reg_ %+ %$j
BasicWindow.asm:107: warning: 3 esi3 3
BasicWindow.asm:107: warning: 3 esi2 2
BasicWindow.asm:107: warning: 3 esi1 1
I don't quite understand the leading number but assume this to be an internal counter??
Keith, sorry for uploading an incomplete project, I was tired and rushed through the "packaging". Here is a complete copy that should allow you to compile.
Regards
Klod
-
Leaning towards a bug in 2.09+.
%xdefine %%reg_%$j %1 works, as expected. Using the context-local counterpart should as well, but it doesn't.
%xdefine %{${reg_%$j} %1 works, and it shouldn't... notice the missing bracket.
Something is amiss.
-
I have been using a helper macro to circumvent this issue:
%macro def 2
%xdefine %1 %2
%endmacro
def %$reg_%+%$j,%1
This seems to work with all versions of Nasm I have tested.
Regards,
Klod