Reputation: 4222
I'm trying to make a simple bootloader that will run from a USB. After several problems, I tried using the following asm code block (that i got from MikeOS):
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
mov si, msg
call move
jmp $
msg db 'Whatever!', 0
move:
mov ah, 0Eh
.print:
lodsb
cmp al,0
je .Done
int 10h
jmp .print
.Done:
ret
times 510-($-$$) db 0
dw 0xAA55
This resulted in L being printed infinite number of times when i tried to boot it from the USB :( Can anyone let me know what i'm doing wrong.
I'm copying it into Sector 0, using dd.
Edit: This somehow doesn't work on my PC but works on my sisters laptop. Anyone have any idea why?
Upvotes: 1
Views: 589
Reputation: 37232
There's no bug in the code you've posted that would explain the symptoms.
Note: There are 2 bugs. It assumes the direction flag is clear and doesn't do a cld
before the lodsb
, but that might cause it to display 'W' followed by strange characters (and not an 'L' repeated). It also doesn't set a value in bh
for the page number used by "int 0x10, ah=0x0E", but that might cause nothing to be displayed (and not an 'L' repeated).
Given the absence of a cause in the code itself; the most likely problem is either a problem with how you copy the resulting binary onto the USB flash (more likely), or a problem with how you assemble the code (less likely).
Upvotes: 1