如何在硬盘上写有BIOS中断13H [英] How to write on hard disk with bios interrupt 13h
问题描述
我想在我自己的boot loader拷贝到硬盘的第一个扇区(512)(我应该使用BIOS中断13h),我发现这个code:
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 ; set BX to the address (not the value) of BlahBlah
mov ah,03h ;When ah=, int13 reads a disk sector
mov al,5 ;Al is how many sectors to read
mov cl,0 ;Sector Id
mov dh,0 ;Head
mov dl,80h ;Drive (0 is floppy)
mov cx,512 ;One sector /2
mov ah, 0x3 ; set function 2h
int 0x13
卜这是行不通的!
bu it does not work!
推荐答案
您code是非常杂乱。为了正确使用 INT 13H
与 AH = 3
,你也需要设置 ES
(其中 BX
所在的领域,如 ES:BX
是地址缓冲器应被读取和写入到硬盘),和 CX
来汽缸和扇区号的组合(气缸= CL [7: 6] || CH
,部门= CL [5:0]
)
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]
).
假设你想从物理地址 5000H
来CHS 0写一个扇区(512字节):硬盘0,你的code 1: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
您也应该记得检查是否进位标志已执行中断后,已完成设置。如果函数已被正确执行时,将是清楚的。如果它被设置,那么 AH
寄存器将包含一个错误code。
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中断13H的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!