NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: georgelappies on April 30, 2012, 05:13:08 PM
-
Hi all
There seems to be an inconsistency between some text when it comes to declaring labels for variables. Some use the ":" and some not.
For instance are the following two data declaration blocks equivalent?
; ----- data declarations -----
i: dw 0 ; set i = 0
A: dw 0
B: dw 0
C: dw 0
D: dw 0
and this one:
; ----- data declarations -----
i dw 0 ; set i = 0
A dw 0
B dw 0
C dw 0
D dw 0
Or does the ":" signify some special meaning?
-
Hi George,
The two data declarations you show are identical. Essentially, Nasm does not require a colon - it's the same thing with or without. However, there's an exception to this if the label (variable name) is the only thing on the line - what Nasm calls an "orphan-label". This can trigger one of Nasm's "suppressible warnings":
http://www.nasm.us/xdoc/2.10/html/nasmdoc2.html#section-2.1.24
In earlier versions of Nasm, the "orphan-labels" warning was disabled by default..
mov esi, my_var
lodbs ; <-typo!
Nasm would assemble this with no indication of a possible problem. Recent versions have this warning enabled by default, and will warn that this "might be an error". Maybe it's not an error, maybe you intended a label by that name and didn't want a colon on it for reasons of your own. You can disable the warning - "-w-orphan-labels" - either on the command line or in the code (you can have warnings "on" for part of the code and "off" for the rest). Or you can ignore the warning - Nasm will assemble it anyway. Or you can put the colon there. It merely serves as a rudimentary "spell checker".
With the exception of this "label alone on a line" situation, Nasm doesn't care if you've got a colon after it or not. Programmer's choice!
Best,
Frank