assemblyx86nasmidentifierreserved-words

Label or instruction expected at start of line while using NASM


I'm getting the error:

label or instruction expected at start of line

in the .data section when defining a string made up of bytes:

st2 db "num3>num1,2", 0xA, 0xD

I looked at the possible solutions but none seem to match what I was looking for, but all of them was either a missed semicolon when typing a comment, or UTF-DOM encoding. (NASM only permits use of ASCII)


Solution

  • st2 is an x87 register name.

    You could use $st2: db ... with the $ forcing NASM to not interpret it as a register, but probably better just to choose a different name.

    Putting a : at the end of a label disambiguates labels from instruction mnemonics (e.g. loop: is a label, loop is the instruction without enough operands), but apparently not for register names. Most people consider it good style to always put a : on every label, even in the .data section (unlike MASM).