I have NASM and Dev-Cpp installed on my system. Dev-cpp comes with the LD (GNU Linker). I am new to assembly code and the processes to create a 32-bit Windows executable from an assembler file. I tried using this:

nasm -f win32 ass.asmnasm -o ass ass.o

I had no success using these commands to create an executable. What is the proper way to assemble (with NASM) and link to generate an executable that will run on 32-bit Windows?

1

Best Answer


One of your comments that doesn't seem to exist anymore did mention that you had Dev-Cpp on installed on your Windows. If you have the Dev-Cpp MinGW bin directory on your path, then the GNU Linker LD is available to you.

I don't know if you are using a 32-bit or 64 GCC with Dev-Cpp, but this should work for both to generate a 32-bit executable:

nasm -f win32 ass.asm -o ass.objld -mi386pe -o ass.exe ass.obj

That will tell NASM to generate a 32-bit Win32 object, and LD will link the object to an i386pe 32-bit Windows executable.

Alternatively you could download the the GoLink linker. Once you extract it onto your path you could do something like:

nasm -f win32 ass.asm -o ass.objGoLink.exe /console ass.obj kernel32.dll user32.dll gdi32.dll 

You may have to specify your code entry point (label) with something like:

GoLink.exe /console /entry _start ass.obj kernel32.dll user32.dll gdi32.dll 

Where _start could be the label where you expect your program to start. You don't need any of the DLL's listed if you aren't calling any of the Win32 API.

If you aren't creating a console application then you can leave off /console