简体   繁体   English

如何使用BIOS中断13h在硬盘上写入

[英]How to write on hard disk with bios interrupt 13h

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: 我想将引导加载程序复制到自身内部硬盘的第一个扇区(512)中(我应该使用BIOS中断13h),发现以下代码:

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! 埠它不起作用!

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, eg 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] ). 为了正确使用AH = 3 int 13h ,还需要设置ESBX所在的段,例如ES:BX是应读写到硬盘的缓冲区的地址)和CX到柱面和扇区号的组合( cylinder = CL[7:6] || CHsector = 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 : 假设您要从物理地址5000h向硬盘0上的CHS 0:0:1写入一个扇区(512字节),您的代码将如下所示:

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. 如果已设置,则AH寄存器将包含错误代码。

BIOS functions have input parameters. BIOS函数具有输入参数。 If you don't get all of the input parameters right, the BIOS function isn't able to guess what you meant. 如果您没有正确输入所有输入参数,则BIOS函数将无法猜测您的意思。 For the BIOS function you're using have a look at: http://www.ctyme.com/intr/rb-0608.htm 有关您使用的BIOS功能的信息,请访问: 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. 据我所知,您缺少CH和ES的合理值,因此BIOS可以将数据从完全不同的地址写入完全不同的扇区。 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. 还要注意,CL是CX寄存器的最低部分-将值加载到CL然后通过将某些内容加载到CX来覆盖它是没有意义的。

BIOS functions return values too. BIOS函数也返回值。 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. 在您的情况下,BIOS可能会返回状态代码,告诉您出了什么问题,并且由于您不进行检查,所以您不知道是否出了什么问题或出了什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM