NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: vLK on March 19, 2010, 07:35:35 AM
-
Hello!
I am quite new to NASM, for some time I've used FASM (NASM syntax is a bit scary for beginners), but in general, I'm also quite new to ASM.
At the moment, I am mostly playing around with this assembler to learn its syntax fully. Much of it I like, and it's been pretty straight forward so far, although this morning I encountered a problem with WinAPI imports and I hope that you can help me..
So.. I'm declaring an extern using the obvious 'extern' directive:
extern Sleep
In my code I then call this a couple of times, this is not very important, it assembles nicely with:
nasm -f win32 -Ox -o code.obj code.s
However when I try to link with this line, using Microsoft LINK, all hell is let loose:
link /ENTRY:main /SUBSYSTEM:console /MACHINE:X86 kernel32.lib code.obj
code.obj : error LNK2001: unresolved external symbol Sleep
code.exe : fatal error LNK1120: 1 unresolved externals
I have tried declaring the symbol _Sleep, __imp__Sleep and __imp__Sleep@4 but it generates the same error.
What am I doing wrong here? Should I maybe just use another linker? Anyone else had these problems?
And another question: Whats the essential difference between a %define and an equ? Is there any differences but the one that equ supports various expressions? Hope I don't appear too nooby :P Thanks!
-
I have tried declaring the symbol _Sleep, __imp__Sleep and __imp__Sleep@4 but it generates the same error.
You pretty much danced around it. IIRC, the STDCALL decoration for that function should be: _Sleep@4
And another question: Whats the essential difference between a %define and an equ? Is there any differences but the one that equ supports various expressions? Hope I don't appear too nooby :P Thanks!
As per NASM Doc Section 3.2.4 (http://www.nasm.us/doc/nasmdoc3.html#section-3.2.4), an equ is for assigning constants, thus it is only evaluated once and cannot be changed.
As per NASM Doc Section 4.1.1 (http://www.nasm.us/doc/nasmdoc4.html#section-4.1.1), a define is a single-line macro, thus it is apart of the preprocessor, can be changed and may be evaluated multiple times.
-
That worked! Thank you for your answers :)
-
A subtle difference between "%define" and "equ" is that a symbol assigned with "equ" goes into the symbol table, and makes it into the executable (at least in Linux). This may have advantages. A symbol defined with "%define" is an "assemble-time only" symbol - no trace of it in the executable (AFAIK).
You could think of "equ" as a "numeric cut-and-paste" and "%define" as a "text cut-and-paste"... (I think...).
Out of curiousity, vLK, what parts of Nasm syntax do you find scary, compared to Fasm?
Best,
Frank
-
Out of curiousity, vLK, what parts of Nasm syntax do you find scary, compared to Fasm?
I'm curious too, as FASM is basically a fusion of TASM and NASM concepts that were favored by the author.