Reputation: 551
I'm following a tutorial that introduce you in the magic world of bootloader.
The easiest example, print a character, works.
Displaying a string gives me some problem: it displays random characters.
It should display 12 characters, starting at the location inside si
register
Here's the Nasm code (build command: nasm.exe bootloader.asm -f bin -o bootloader.bin
)
[bits 16]
[org 0]
start:
mov al, 68
mov ah, 0x0E
mov bh, 0x00
mov bl, 0x07
mov si, helloWorld
call printString
jmp $
printString:
mov dx, 0
._loop:
mov al, [si]
int 0x10
inc si
inc dx
cmp dx, 12
jl ._loop
ret
helloWorld:
db 'AAAAAAAAAA'
times 510 - ($ - $$) db 0
dw 0xAA55
Then I create the .img file with dd.exe if=bootloader.bin of=bootloader.img count=1 bs=512
It boots correctly in QEMU (qemu-system-i386.exe
) (well, it loads, because my bootloader still not boot) (maybe it's a problem of QEMU -difficoult-)
What's the problem in my code?
Upvotes: 0
Views: 712
Reputation: 1
Yes you need ORG 0x7C00, so the addressing starts at 7C00h. You also need to set up the DS (data segment) register before accessing data on [SI] as there is no guarantee all BIOSES will have set it to 0.
Just do: MOV DX,CS MOV DS,DX at your start: label
After you have set up the DS you can access any data structures there.
For reference here are the first instructions of a Microsoft boot sector (after the jmp):
XOR CX,CX
MOV SS,CX
MOV SP,7BF4h
MOV ES,CX
MOV DS,CX
Upvotes: 0
Reputation: 1298
You should use [org 0x7c00]
since that is where your bootloader will be loaded. I suggest you read more about boot sequence from this OSDev Wiki article.
Upvotes: 1