Bluefox815
August 5th, 2010, 11:30 PM
I am trying to use nasm to compile assembly code into an object file, and then link the object file to an EXE. My first attempt was to use the following command lines:
nasm -f coff -o hello.o hello.asm
ld -o hello.exe hello.o
Where "ld" is the linker program that comes with the MinGW compiler tools. The program compiles fine, and seems to link fine, but when I try to run the program Windows XP (32-bit) gives me an error saying the program has encountered a problem and needs to close.
I have tried using the "win32" format on nasm, but I get the same result.
Here is my code (which tries to print a string and exit):
section .text
global start ;I've tried omitting this, I've also tried underscores and replacing start with "main"
start: ;this has always matched the label given by global
mov ah, 0x09 ;print string
mov edx, my_str
int 21h
mov ax, 0x4C00 ;quit
int 21h
section .data
my_str: db "Hello World!", 13, 10, '$'
Here is a summary of my environment:
nasm (compile ASM, tried win32 and coff outputs)
MinGW linker (linking object files, I haven't tried other linkers)
Windows XP 32-bit (host operating system)
nasm -f coff -o hello.o hello.asm
ld -o hello.exe hello.o
Where "ld" is the linker program that comes with the MinGW compiler tools. The program compiles fine, and seems to link fine, but when I try to run the program Windows XP (32-bit) gives me an error saying the program has encountered a problem and needs to close.
I have tried using the "win32" format on nasm, but I get the same result.
Here is my code (which tries to print a string and exit):
section .text
global start ;I've tried omitting this, I've also tried underscores and replacing start with "main"
start: ;this has always matched the label given by global
mov ah, 0x09 ;print string
mov edx, my_str
int 21h
mov ax, 0x4C00 ;quit
int 21h
section .data
my_str: db "Hello World!", 13, 10, '$'
Here is a summary of my environment:
nasm (compile ASM, tried win32 and coff outputs)
MinGW linker (linking object files, I haven't tried other linkers)
Windows XP 32-bit (host operating system)