Assembly language examples using NASM on Windows
The build environment
Assembler
All examples are assembled with NASM.
Make sure to use the correct output format, 32 bit or 64 bit.
- nasm -f win32 program.asm -o program.obj
- nasm -f win64 program.asm -o program.obj
Linker
All examples can be linked with either GoLink or Polink (part of Pelles C).
The Microsoft documentation for each API function will give which .lib / .dll files to include.
It's easier to get started with GoLink as it uses the .dll directly, so there's no need for the .lib files.
- golink /entry:Start /console kernel32.dll user32.dll program.obj
- golink /entry:Start kernel32.dll user32.dll program.obj
Make sure to use the correct subsystem (console or windows), and library directory for 32 or 64 bit.
- polink /ENTRY:Start /SUBSYSTEM:CONSOLE /LIBPATH:c:\lib32 kernel32.lib user32.lib program.obj
- polink /ENTRY:Start /SUBSYSTEM:WINDOWS /LIBPATH:c:\lib32 kernel32.lib user32.lib program.obj
- polink /ENTRY:Start /SUBSYSTEM:CONSOLE /LIBPATH:c:\lib64 kernel32.lib user32.lib program.obj
- polink /ENTRY:Start /SUBSYSTEM:WINDOWS /LIBPATH:c:\lib64 kernel32.lib user32.lib program.obj
Windows import libraries
These can be obtained from any of the following packages.
Constants
The constants needed in the examples are defined within each program.
It's tricky to find a compete list of the constant names and their values on the Microsoft website. The best place to obtain them is
a file called windows.inc from the MASM32 package (the other definitions in that file are not compatible with NASM)
Debugging