I am writing a boot sector that boots up, prints a message saying "Hello world." and enters an infinite loop. I am using int 0x10 to print characters of the message.
I have assembled the code using nasm and tested it on qemu. It works fine and the message is displayed. I also copied the boot sector to a USB drive using the command
dd if=welcome_message of=/dev/sdb bs=512 count=1
and booted from the USB drive using qemu
qemu-system-x86_64 /dev/sdb
The message is displayed. But when I restart my PC and boot from USB, it boots up but nothing is displayed. The cursor does move forward according to the length of the message but nothing is displayed. What am I missing ? It appears that the characters are displayed but somehow they are not visible. I have attached the code
;Print a welcome message after booting
[org 0x7c00] ;BIOS loads this code at 0x7c00
mov ah, 0x0e ;For Using BIOS to print a character
mov cl, len ;Used as counter inside the loop, so load with length
inc cl
mov si, welcome ;Used as pointer to the character string
loop:
mov al, [si] ;get the character in al
int 0x10 ;Print the character
inc si ;Point to next character
dec cl ;Decrement counter
jnz loop ;Keep printing until you reach end of the welcome message
jmp $ ;Loop forever
welcome: db "Hello World ."
len equ $-welcome
times 510 - ($-$$) db 0 ;Put 0s till 510
dw 0xaa55
EDIT 0 : Setting DS to 0 starts the printing. But some characters are not printed. The expected output is "Hello World!" but I get "Hel orld ". What might be the problem ?
;Print a welcome message after booting
[bits 16]
[org 0x7c00] ;BIOS loads this code at 0x7c00
mov ax, 0
mov ds, ax ;Initialize data segment register
mov ah, 0x0e ;For Using BIOS to print a character
mov cl, len ;Used as counter inside the loop, so load with length
inc cl
mov si, welcome
loop:
mov al, [si] ;get the character in al
int 0x10 ;Print the character
inc si
dec cl
jnz loop ;Keep printing until you reach end of the welcome message
jmp $ ;Loop forever
welcome: db "Hello World!"
len equ $-welcome
times 510 - ($-$$) db 0 ;Put 0s till 510
dw 0xaa55
EDIT 1: FInally I got the correct output. Check the comment thread for solution.