NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on October 05, 2007, 08:20:15 PM
-
hi,
i'm new to nasm and experiencing problems trying to write a winapi "hello world".
the idea is simple: use messagebox to display the text. unfortunately i'm getting
the error "parser: instruction expected" on the "IMPORT".
my code:
[BITS 32]
[SEGMENT .code]
EXTERN MessageBoxA
IMPORT MessageBoxA user32.dll
mov eax, 0
ret
i'm typing nasm 1.asm -f coff to build object file.
what's wrong?
thanks in advance.
felix =)
-
The import directive only works with the omf object format.
Try:
nasm 1.asm -f obj
----
nmt
-
Thanks. Now it works, but now I can't build the exe with gcc?
ld seems not to recognize that omf format at all. how do i
build that obj file to exe? (i'm using cygwin) ?
felix =)
-
I do it in this way (mingw, cygwin)...
1. Source code:
bits 32
extern _MessageBoxA@16
global entry
section .code
entry:
push byte 0
push msg
push caption
push byte 0
call dword _MessageBoxA@16
ret
msg db "hell", 0
caption db "message", 0
; ------
2. Makefile:
NAME=1
$(NAME).exe:$(NAME).obj
ld $(NAME).obj -o $(NAME).exe -e entry --subsystem windows -luser32
$(NAME).obj:$(NAME).asm
nasm $(NAME).asm -fwin32
run:$(NAME).exe
./$(NAME).exe
clean:
rm *.exe *.obj
; -----
3. Command line from msys or cygwin:
make run
; -----
You can write some macro to do it easy. We can help you.
-----
nmt