What is the exact NASM equivalent of below MASM code?
; Simple lookup table (.const section data is read-only)
.const
const_array dword 0, 1, 1, 2, 3, 5, 8, 13, 21
Because the .const
MASM directive denotes a read-only segment, you have to use the NASM equivalent section .rdata
1 which creates a segment/section which is readable, but not writeable.
You can put DWORDs anywhere by using the DD
directive; see Section 3.2.1 of the manual.
The final result could look like this:
section .rdata
const_array: dd 0, 1, 1, 2, 3, 5, 8, 13, 21
A :
after label names is always recommended in NASM.
When the first token on the line isn't recognized as an instruction mnemonic NASM will assume it's a label. But it's a good habit to always use :
to make that unambiguous.
Footnote 1:
Windows uses .rdata
. Some other OSes including Linux use section .rodata
for read-only non-executable data.