Getting Started with Assembly Programming: Complete Setup Guide
1. Choose an Assembly Compiler / Assembler
There are several popular options:
There are several popular options:
- NASM (Netwide Assembler) — Cross-platform, free, widely used.
- MASM (Microsoft Macro Assembler) — Windows-only, integrates with Visual Studio.
- GAS (GNU Assembler) — Comes with GCC, good for Linux/macOS.
2. Download and Install the Assembler
- NASM: https://www.nasm.us/
- Download the latest stable version for your operating system.
- Install NASM (Windows: run installer, Linux/macOS: usually `sudo apt install nasm` or `brew install nasm`).
3. Choose an Editor / IDE
You can use any text editor:
You can use any text editor:
- VS Code (recommended, free, cross-platform)
- Notepad++ (Windows)
- Vim / Nano / Emacs (Linux/macOS)
4. Verify NASM Installation
Open a terminal or command prompt and type:
You should see the NASM version number.
Open a terminal or command prompt and type:
| nasm -v |
5. Writing Your First Assembly Program
Create a new file called hello.asm. Here’s a simple NASM x86 example for 64-bit Linux that prints "Hello World!":
Create a new file called hello.asm. Here’s a simple NASM x86 example for 64-bit Linux that prints "Hello World!":
|
section .data msg db "Hello World!",0xA len equ $ - msg section .text global _start _start: mov rax, 1 ; syscall: write mov rdi, 1 ; file descriptor: stdout mov rsi, msg ; message to write mov rdx, len ; message length syscall mov rax, 60 ; syscall: exit xor rdi, rdi ; status 0 syscall |
6. Assemble and Link the Program
Open a terminal in the folder containing hello.asm and run:
You should see: Hello World!
Open a terminal in the folder containing hello.asm and run:
| nasm -f elf64 hello.asm -o hello.o |
| ld hello.o -o hello |
| ./hello |
7. Notes on Windows with NASM and MASM
- Windows programs often require linking with C runtime or using Win32 syscalls.
- For NASM on Windows, you can use MinGW or Visual Studio tools to link:
nasm -f win64 hello.asm -o hello.obj link hello.obj /subsystem:console - MASM can be used inside Visual Studio or via the ml.exe command line.
8. Learning Next Steps
- Experiment with registers, arithmetic, loops, and conditional jumps.
- Learn system calls for your OS (Linux: `write`, `read`, `exit`; Windows: `MessageBox`, `ExitProcess`).
- Debug with GDB (Linux) or WinDbg (Windows) to step through assembly instructions.
- Read NASM / MASM manuals to understand directives like section, global, equ, etc.