我正在嘗試制作一個作業系統并且我已經撰寫了兩個程式:boot.asm和loader.asm,編譯程序非常成功,但是當我使用bochs除錯我的程式時,它卡在了命令'int 13h'。有沒有人解決這個問題?
這是我的代碼:
啟動.asm:
org 07c00h
...
BPB_SecPerTrk dw 18
BS_DrvNum db 0
...
ReadOneSector:
push bp
mov sp, sp
sub esp, 2
mov byte [bp-2], cl
push bx
mov bl, [BPB_SecPerTrk]
div bl
inc ah
mov cl, ah
mov dh, al
shr al, 1
mov ch, al
and dh, 1
pop bx
mov dl, [BS_DrvNum]
Label_Go_Reading:
mov ah, 2
mov al, byte [bp-2]
int 13h ; the program gets stuck when running this line
jc Label_Go_Reading
add esp, 2
pop bp
ret
...
times 510-($-$$) db 0
dw 0xaa55
這是除錯器的輸出:
<bochs:45> n
Next at t=14041939
(0) [0x000000007ca1] 0000:7ca1 (unk. ctxt): mov al, byte ptr ss:[bp-2] ; 8a46fe
<bochs:46> n
Next at t=14041940
(0) [0x000000007ca4] 0000:7ca4 (unk. ctxt): int 0x13 ; cd13
<bochs:47> n ;the program gets stuck when executing this line
誰能告訴我為什么程式會卡住以及如何解決這個問題(我想也許之前的代碼不能讓'int 13h'運行)
uj5u.com熱心網友回復:
ReadOneSector: push bp mov sp, sp <<<<<<<<<<<<<<<<<<<<<<<<<<<< sub esp, 2 mov byte [bp-2], cl
第三行有錯別字。您要加載BP暫存器,而不僅僅是 nop on SP!
下一個解決方案避免將區域變數放在堆疊上:
; IN (ax,es:bx,cl)
ReadOneSector:
push bp
mov ch, 2 ; CH Function number
mov bp, cx ; CL Sector count
push bx
mov bl, [BPB_SecPerTrk]
div bl
inc ah
mov cl, ah
mov dh, al
shr al, 1
mov ch, al
and dh, 1
pop bx
mov dl, [BS_DrvNum]
Label_Go_Reading:
mov ax, bp ; -> AH function number, AL sector count
int 13h
jc Label_Go_Reading
pop bp
ret
如果這個例程被命名為“Read One Sector”,那么為什么還有一個引數(in CL)來表示扇區的數量?
無論如何,對于讀/寫多個扇區,最好讀/寫一個扇區并回圈重復(查找多軌問題):
; IN (ax,es:bx,cl)
ReadMultipleSectors:
pusha
movzx bp, cl ; CL Sector count 1
NextSector:
push ax ; (1)
push bx ; (2)
mov bl, [BPB_SecPerTrk]
div bl
inc ah
mov cl, ah
mov dh, al
shr al, 1
mov ch, al
and dh, 1
pop bx ; (2)
mov dl, [BS_DrvNum]
Label_Go_Reading:
mov ax, 0201h
int 13h
jc Label_Go_Reading
pop ax ; (1)
inc ax ; Next sector number
add bx, 512 ; Next sector buffer
dec bp
jnz NextSector
popa
ret
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/443210.html
上一篇:指令集如何標準化?
