2
votes

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
1
As usual, you forgot to intialize DS. - Jester
Could you please explain what does this DS do.I am beginner in assembly. - skesh
I have Bootloader Tips in another SO answer. Setting up the segment register like DS may be needed. When you say hard drive do you mean you boot on real hardware? - Michael Petch
@skesh DS is the data segment register. Its content is multiplied with 16 and added to every address you use to fetch data. At the beginning of your code, you need to initialize it e.g. to zero by writing something like xor ax,ax and then mov ds,ax. - fuz
Try adding xor ax,ax mov ds,ax before MOV SI, HelloString - Michael Petch

1 Answers

0
votes

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