I'm trying to compile assembly code with NASM using CMake-generated project for Visual Studio on Windows 11.
I ran nasm -f win64
directly from the command line and it reports the same error as from VS:
hello_world.asm:1: error: parser: instruction expected
My assembly code (for 32-bit Linux, not Windows):
section .text
global _start ; необходимо для линкера (ld)
_start: ; сообщает линкеру стартовую точку
mov edx,len ; длина строки
mov ecx,msg ; строка
mov ebx,1 ; дескриптор файла (stdout)
mov eax,4 ; номер системного вызова (sys_write)
int 0x80 ; вызов ядра
mov eax,1 ; номер системного вызова (sys_exit)
int 0x80 ; вызов ядра
section .data
msg db 'Hello, world!', 0xa ; содержимое строки для вывода
len equ $ - msg ; длина строки
I tried to run build with all possible presets (Debug/Release/x86/x64 etc.) but still no results.
My NASM build is 2.16.02rc6
. I asked another programmer to assemble this code for me with exact same parameters and NASM build and it worked for him.
Even the program below cannot be assembled, with exact same error as before
section .text
global main
main:
ret
The assembly source file was encoded in UTF-8 with BOM.
NASM doesn't accept a BOM, only plain UTF-8 or ASCII.
(It does allow non-ASCII UTF-8 for things like label names and comments.)
Changing the source file encoding to ASCII resolved the issue.