Nasm vs as
nasm (Netwide Assembler) and as (GNU Assembler) are two different assemblers for x86 and x86-64 assembly language, and they have different syntax and conventions.
Key Differences:
Section and Global Directives:
nasmuses.section .textand.global _start.asusessection .textandglobal _start.
Register and Instruction Syntax:
nasmuses%prefix for registers and$for immediate values.asdoes not use%for registers and uses$for immediate values.
Comment Syntax:
nasmuses;for comments.asuses#for comments.
Flags:
nasm Flags:
elf32orelf64: Specifies the output format as 32-bit or 64-bit ELF.
Example:
nasm Syntax:
section .text
global _start
_start:
mov rax, 60 ; Syscall number for exit
xor rdi, rdi ; Exit code 0
syscall ; Invoke the syscall
as Syntax:
.section .text
.global _start
_start:
mov $60, %rax # Syscall number for exit
xor %rdi, %rdi # Exit code 0
syscall # Invoke the syscall
These differences are due to the design choices and conventions adopted by the developers of each assembler.
Last modified: 14 January 2025