I want to copy my boot loader to first sector(512) of hard disk within itself (I should use bios interrupt 13h) and I found this code:
mov bx, buffer1 ; se
Your code is very messy. In order to properly use int 13h
with AH = 3
, you need to also set ES
(the segment in which BX
resides, e.g. ES:BX
is the address of the buffer which should be read and written to the hard disk), and CX
to a combination of the cylinder and sector number (cylinder = CL[7:6] || CH
, sector = CL[5:0]
).
Assuming that you want to write one sector (512 bytes) from the physical address 5000h
to CHS 0:0:1 on hard disk 0, your code would look something like this :
xor ax, ax
mov es, ax ; ES <- 0
mov cx, 1 ; cylinder 0, sector 1
mov dx, 0080h ; DH = 0 (head), drive = 80h (0th hard disk)
mov bx, 5000h ; segment offset of the buffer
mov ax, 0301h ; AH = 03 (disk write), AL = 01 (number of sectors to write)
int 13h
You should also remember to check whether the Carry Flag has been set after executing the interrupt. It will be clear if the function has been executed properly. If it's set, then the AH
register will contain an error code.