彙編語言(王爽)實驗十七

實驗十七

用面號、磁道號、扇區號訪問磁盤不太方便,考慮對它們進行統一編號

方法如下,稱此編號爲邏輯扇區編號

image-20200331181308238

邏輯扇區號=(面號*80 + 磁道號)*18 + 扇區號-1
反過來
面號=int(邏輯扇區號/1440)
磁道號=int(rem(邏輯扇區號/1440)/18)
扇區號=rem(rem(邏輯扇區號/1440)/18)+1
int():取商
rem():取餘數

安裝一個新的int 7ch中斷例程,實現通過邏輯扇區號對軟盤進行讀寫

ah傳遞功能號:0表示讀 1表示寫

dx傳遞邏輯扇區號

es:bx指向讀出/寫入數據的內存區

提示:可調用int 13h進行實際的讀寫

assume cs:code

code segment
	start:	mov ax,cs
			mov ds,ax
			mov si,offset int7cstart
			
			mov ax,0
			mov es,ax
			mov di,200h
			
			mov cx,offset int7cend-offset int7cstart
			cld
			rep movsb
			
			cli
			mov ax,0
			mov ds,ax
			mov word ptr ds:[4*7ch],200h
			mov word ptr ds:[4*7ch+2],0
			sti
			
			mov ax,4c00h
			int 21h
            
int7cstart:	cmp ah,1	
			ja ok		; 違法的功能號
			
			push ax		; 保護現場
			push bx
			push cx
			push dx
			
			push ax		; ah中存着功能號
			
			mov ax,dx	; 傳遞邏輯扇區號
			mov dx,0
			mov cx,1440
			div cx
			push ax		; ax保存得到的商,即面號,入棧保存
			
			mov cx,18
			mov ax,dx	; 所得結果的餘數傳遞給ax,繼續做除法
			mov dx,0
			div cx
			push ax		; ax保存得到的商,即磁道號
			inc dx		; 計算出扇區號
			push dx		; 入棧保存
			
			pop ax
			mov cl,al	; 扇區號
			pop ax
			mov ch,al	; 磁道號
			pop ax
			mob dh,al	; 面號
			mov dl,0	; 驅動器號
			pop ax		; 彈出ax,其中ah中存着功能號
			mov al,1	; 扇區數
			
			cmp ah,0
			je read
			cmp ah,1
			je write
			
	read:	mov ah,2
			jmp short func
	write:	mov ah,3
			jmp short func
	func:	int 13h
			
			pop dx		; 恢復現場
			pop cx
			pop bx
			pop ax
			
      ok:	iret
      
  int7cend:	nop
  
  code ends
  end start
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章