I am learning about the bootloaders, and I used this code from here https://wiki.osdev.org/Babystep2 to create 'Hello,World!' bootloader.
; boot.asm
mov ax, 0x07c0
mov ds, ax
mov si, msg
cld
ch_loop:lodsb
or al, al ; zero=end or str
jz hang ; get out
mov ah, 0x0E
mov bh, 0
int 0x10
jmp ch_loop
hang:
jmp hang
msg db 'Hello World', 13, 10, 0
times 510-($-$$) db 0
db 0x55
db 0xAA
The above code works perfectly fine. But when I tried to modify it to use the standard NASM syntax as below, it prints nothing and there are no error messages!
section .data
msg: db 'Hello, World!', 13, 10, 0
section .text
global _start
_start:
mov ax, 0x07c0
mov ds, ax
mov si, msg
cld
_ch_loop:
lodsb
or al, al
jz _hang
mov ah, 0x0E
mov bh, 0
int 0x10
jmp _ch_loop
_hang:
jmp _hang
times 510-($-$$) db 0
db 0x55
db 0xAA
The above code doesn't print anything and there is no error message. However when I run the below code it works!
section .text
global _start
_start:
msg: db 'Hello, World!', 13, 10, 0
mov ax, 0x07c0
mov ds, ax
mov si, msg
cld
_ch_loop:
lodsb
or al, al
jz _hang
mov ah, 0x0E
mov bh, 0x00
int 0x10
jmp _ch_loop
_hang:
jmp _hang
times 510-($-$$) db 0
db 0x55
db 0xAA
What is going wrong here. Why section .data is not working as expected?