How to write on hard disk with bios interrupt 13h

烈酒焚心 提交于 2019-12-03 09:12:39
Daniel Kamil Kozar

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.

BIOS functions have input parameters. If you don't get all of the input parameters right, the BIOS function isn't able to guess what you meant. For the BIOS function you're using have a look at: http://www.ctyme.com/intr/rb-0608.htm

As far as I can tell, you're missing sane values for both CH and ES, so the BIOS can write data from a completely different address to a completely different sector. Also note that CL is the lowest half of the CX register - there's no point loading a value into CL and then overwriting it by loading something into CX.

BIOS functions return values too. In your case the BIOS may be returning a status code that tells you what went wrong, and because you don't check you don't know if anything went wrong or what it was if it did.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!