Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Bootloader program to print helloworld is not working

I am trying to learn a simple helloworld bootloader program. referring this link. I have successfully generated the binary file for this assembly code using nasm assembler and run with a emulator bochs and it works fine. But when I did the same thing directly with a hard disk I am not able to print the string to screen.

Please find below the code I have used.

[BITS 16]
[ORG 0x7C00]

MOV SI, HelloString
CALL PrintString
JMP $

PrintCharacter:
    MOV AH, 0x0E
    MOV BH, 0x00
    MOV BL, 0x07
    INT 0x10
    RET

PrintString:
next_character:
    MOV AL, [SI]
    INC SI
    CALL PrintCharacter
    OR AL, AL
    JZ exit_function
    JMP next_character
exit_function:
    RET

HelloString db "Pell",0 

TIMES 510 - ($ - $$) db 0 
DW 0xAA55
like image 853
skesh Avatar asked Feb 04 '26 01:02

skesh


1 Answers

You need to initialise the segment registers before you do anything else or the program will crash as you cannot access the data.

[BITS 16]
[ORG 0x7C00]

XOR AX, AX
MOV DS, AX

MOV SI, HelloString
CALL PrintString
JMP $

PrintCharacter:
    MOV AH, 0x0E
    MOV BH, 0x00
    MOV BL, 0x07
    INT 0x10
    RET

PrintString:
next_character:
    MOV AL, [SI]
    INC SI
    CALL PrintCharacter
    OR AL, AL
    JZ exit_function
    JMP next_character
exit_function:
    RET

HelloString db "Pell",0 

TIMES 510 - ($ - $$) db 0 
DW 0xAA55
like image 103
Alex Boxall Avatar answered Feb 06 '26 14:02

Alex Boxall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!