如何用BIOS中断13h向硬盘写入
我想将引导加载程序复制到硬盘的第一个扇区(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
但是它不起作用!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的代码非常混乱。为了正确使用
int 13h
和AH = 3
,您还需要设置ES
(BX
所在的段) code> 驻留,例如ES:BX
是应该读取和写入硬盘的缓冲区的地址),CX
是柱面和扇区的组合数字(<代码>圆柱体 = CL[7:6] || CH,扇区 = CL[5:0]
)。假设您想从物理地址
5000h
向硬盘 0 上的 CHS 0:0:1 写入一个扇区(512 字节),您的代码将如下所示:您还应该记住检查执行中断后进位标志是否已设置。函数是否正确执行就一目了然了。如果已设置,则
AH
寄存器将包含错误代码。Your code is very messy. In order to properly use
int 13h
withAH = 3
, you need to also setES
(the segment in whichBX
resides, e.g.ES:BX
is the address of the buffer which should be read and written to the hard disk), andCX
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 :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 功能有输入参数。如果您没有正确输入所有参数,BIOS 功能将无法猜测您的意思。对于您正在使用的 BIOS 功能,请查看:http://www.ctyme。 com/intr/rb-0608.htm
据我所知,您缺少 CH 和 ES 的正常值,因此 BIOS 可以将数据从完全不同的地址写入完全不同的扇区。另请注意,CL 是 CX 寄存器的最低半部分 - 将值加载到 CL 中,然后通过将某些内容加载到 CX 中来覆盖它是没有意义的。
BIOS 函数也返回值。在您的情况下,BIOS 可能会返回一个状态代码,告诉您出了什么问题,并且因为您不检查,所以您不知道是否出了什么问题,或者如果出了问题是什么。
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.