Second-Stage Bootloader Bug
Posted: Thu Dec 11, 2008 5:00 pm
Hi. I'm building a second-stage bootloader. I want it to display a "hello world" message. My problem is that it doesn't. I've made two versions of the program. The first displays the message with some garbage characters before it, the second does not display it at all. Both programs are fairly simple and straightforward, so I can't see what's going wrong.
Here's the first version, which displays garbage before the Hello World message:
And here's the second version, that doesn't display the message at all (it does display the final 'Z' char though).
The first-stage bootloader itself is fairly simple. And it works: In both cases the program is loaded and displays the final Z character, and I've also used it to load another hello world program that displayed the message character by character without using strings and SI, and that one worked fine.
Can anyone pick out the bug in either one of these programs? Thanks!
Here's the first version, which displays garbage before the Hello World message:
Code: Select all
; Update the segment registers
mov ax, cs
mov ds, ax
mov es, ax
HelloString db "Hello World",0
MOV SI, HelloString ;Store string pointer to SI
print:
LODSB ;AL=memory contents at DS:SI
OR AL, AL ;Check if value in AL is zero (end of string)
JZ loop ;If end then return
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
JMP print ; Print next character
loop:
MOV AL, 'Z' ;I'll print a char to see that it ended
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
JMP $ ;Infinite loop
Code: Select all
JMP beginningofprogram
print:
LODSB ;AL=memory contents at DS:SI
OR AL, AL ;Check if value in AL is zero (end of string)
JZ loop ;If end then return
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
JMP print ; Print next character
beginningofprogram:
; Update the segment registers
mov ax, cs
mov ds, ax
mov es, ax
MOV SI, HelloString ;Store string pointer to SI
JMP print ; Print next character
loop:
MOV AL, 'Z' ;I'll print a char to see that it ended
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
JMP $ ;Infinite loop
HelloString db "Hello World",0
Can anyone pick out the bug in either one of these programs? Thanks!