skesh
skesh

Reputation: 161

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

Upvotes: 2

Views: 360

Answers (1)

Alex Boxall
Alex Boxall

Reputation: 571

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

Upvotes: 1

Related Questions