NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Gerhard on February 09, 2013, 07:50:34 PM
-
Hi,
I'm a human and not a Spam Bot.
I'm trying to assemble the following small file with: nasm -f win32 mesbox.asm.
[BITS 32] ; 32 bit segment
%include "win32n.inc"
extern ExitProcess
IMPORT ExitProcess kernel32.dll
extern MessageBoxA
IMPORT MessageBoxA user32.dll
section .data ; data
title db '32 bit Windows and assembly language', 0
msg db 'Hello World!', 0
Error dd 0
section .text ; code
..start
push dword MB_ICONHAND + MB_OKCANCEL
push dword title
push dword msg
push dword 0
call MessageBoxA
push dword Error
call ExitProcess
That generates the following error messages:
mesbox.asm:6: error: parser: instruction expected
mesbox.asm:8: error: symbol `IMPORT' redefined
mesbox.asm:8: error: parser: instruction expected
I've used the following nasm version:
NASM version 2.10.07 compiled on Jan 2 2013
under Windows XP, SP3 inside VirtualPC. What's wrong? Any help is appreciated. Thank you.
Gerhard
-
IMPORT (and for that matter "..start") is a feature of the OMF object format ("-f obj") and does not work with the MS-COFF object format ("-f win32"). You should assemble it with: nasm -f obj mesbox.asm
-
Synfire,
thank you for the fast answer. It works. Is there a better way to assemble that kind of Win32 files?
Gerhard
-
I'm a human and not a Spam Bot.
Hi Gerhard - I never would have guessed that from the question! :)
Well... "import" is known only to "-f obj" (it is provided as a macro by the NASMX package). The special "..start" label is also known only to "-f obj". IF you're going to use "-f obj", you'll also need to specify "use32" on both (all) of the section declarations ("-f obj" defaults to 16-bit code). You will also need to use "call [MessageBox]" and "call [ExitProcess]". I don't know why this is, but it goes along with "import". Alink should link this - I'm not sure about other linkers.
If you're going to stick with "-f win32" (which I think I would recommend), comment out (or delete) the "import" lines. Change "..start" to "_start" and add "global _start". If you're using GoLink, you can add "kernel32.dll" and "user32.dll" to the command line. Other linkers may require a "library"(?)...
I haven't run Windows for a long time (win98), so this is all "from memory" or "so I've been told". Poke around and you should find examples - and example linker command lines...
Best,
Frank
Edit: I see Bryant has already told you that. Well... I'll post anyway...
-
Frank,
thank you for the answer. I'll check the nasmx package for examples.
Hi Gerhard - I never would have guessed that from the question! :)
I wrote this for the moderators, because it's a bit strange always put together the image puzzle before one can answer or open a new topic.
Gerhard
-
Fortunately, I got signed up before I had to "guess the puzzle". I hate those things - often give up in frustration! I'm better at "guess why my code doesn't work". :)
Hope you won't have to do that every time!
Best,
Frank
-
Hi Frank,
Hope you won't have to do that every time!
Best,
Frank
I hope so, too.
Gerhard
-
If you are programming on Windows, I definitely suggest using GoLink. It's a really good linker!
If you're using GoLink, you can add "kernel32.dll" and "user32.dll" to the command line. Other linkers may require a "library"(?)...
In regards to what Frank said here, you might also look the following post:
Re: Using "#DYNAMICLINKFILE" in golink (http://forum.nasm.us/index.php?topic=1122.msg4199#msg4199)
The method described there will allow you to tell GoLink what DLL's you are linking against without having to pass them on the command line.
-
Hi Bryant,
thank you for the informative link; I'll check it out.
If you are programming on Windows, I definitely suggest using GoLink. It's a really good linker!
I'm writing code for Windows and Linux. You're right: GoLink is a good linker and it comes together with the latest nasmx package. Another alternative is PoLink from Pelle's C; that's a good linker, too.
Gerhard