I've got this simple assembly program asm1.asm, but I get an error when trying to compile it. This is the code
;--- constant variables ---
SECTION .data
    msg: db "Hello World!", 10, 0; 10: carriage return, 0: NULL end of msg (stop)
;--- dynamic variables ---
; SECTION .bss
;--- assembler code ---
SECTION .text
extern _printf
global _main                    ;
_main:                          ; void main() {
    push ebp ;basepointer       ;   /* creation of the stack */
    mov ebp, esp ;stackpointer  ;
    push msg                    ;   /* pushing memory address */
    call _printf                    ;   /* call printf */
    mov esp, ebp                ;   /* function body */
    pop ebp                     ;
    return;                     ; }
I get this error
C:\Users\David\Desktop>nasm -f elf asm1.asm
asm1.asm:23: warning: label alone on a line without a colon might be in error
I'm new to assembly so I guess it's just something minor but could someone please tell me what is causing the warning?
What's with the return; line?  That's not an x86 instruction name, so the assembler treats it as equivalent to return: and warns you about it in case that's not what you meant.
x86's return instruction is called ret.
In NASM syntax, a label without a : is allowed as a way to define a symbol, but it's deprecated because of the ambiguity with typoed instructions / directives, or new instruction mnemonics that this version of NASM doesn't recognize yet.  (With a :, you can even use instruction names as labels, like loop:)  -w+orphan-labels is on by default.
https://nasm.us/doc/nasmdoc3.html#section-3.1 Layout of a NASM Source Line documents this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With