There are several problems in your code:
In your first code sample:
1.1. You should locate code you expect to have some output somwhere else than on
0x7c00
. use for example0x8000
instead.1.2. You set mode
0x12
, that's good, but why are you trying to output textA
? Mode0x12
is used for pixel writing, BIOS won't write character to VGA memory - or it will, but VGA expects different data, so it will have some unreadable output.1.3. You should stop code execution, or you'll get
invalid opcode
/lock prefix not allowed
exceptions.In your second code sample, first part:
2.1. You want to read
track0,sector1
on HDD. That's good, buttrack0,sector1
is place where bootloader is located.2.2. On the line
mov bx, 0x7c00
- why are you loading everything on0x7c00
?2.3. Function
3
of interrupt0x13
writes sectors, why are you writing?2.4. You should actually check carry flag if it's set, before checking
AH
.2.5. Again, why are you jumping on the start of bootloader (
0x7c00
)?Second code sample, second part
3.1. Pushing something in bootloader
s code is actually pushing value to small stack set up by BIOS. You don't retrieve value of
AXlater, so be careful if you want to
call` this code in future. 3.2. Finally, I don't understand your rebooting. Why are you doing it?
Here I have working example:
;---------------
;BOOTLOADER
; - loads second sector from disk and executes it
;---------------
start:
xor ax, ax
mov es, ax
mov bx, 0x8000 ;loading to 0x8000
mov cx, 2 ;reading second sector, track 0
mov al, 1 ;just one sector
mov ah, 02 ;function 02: read sectors from disk (CHS)
mov dx, 0x80 ;1st HDD, head 0
int 0x13
jmp 0x800:0
times 510-$ db 0
dw 0xAA55
;---------------
;SECOND STAGE
; - prints some characters
; - stops execution
;---------------
stage2:
mov ah, 0x0E ;function 14: teletype output
mov al, 'A' ;printing 'A' (0x41)
mov bl, 0x0F ;white text on black background
mov bh, 0x0 ;page 0
int 0x10 ;print!
jmp $ ;stop execution
times 1024-$ db 0 ;align