NASM Coding: Basics - Examples
msg db "Hello", 0
In the code line above, we define a variable named msg
whose content is the string literal Hello
followed by the null character (0
) whose purpose is to act as the string's endpoint. The directive (= pseudo-instruction) db
tells the computer to store that data as raw 8-bit bytes in the .data section of the executable.
buffer resb 64
This line in the .bss section declares a variable with the name buffer
, and tells the computer to reserve 64
bytes of space for it using the resb
directive, whose purpose is to "Reserve Byte(s)".
mov rax, 1
Here, we copy the number 1
into the rax
64-bit register in the CPU using the mov
instruction, which you will find in the .text section.