2016-03-15 25 views
2

我寫了下面的程序,但它不起作用。我輸入的文件名爲dur.txt。它返回AX = 4C03。爲什麼它不起作用,我該如何糾正它?在MSDOS中,請求輸入一個現有文件名然後刪除它

.model tiny 
.data 
    max1 db 32 
    act1 db ? 
    inp1 db 30 dup(0) 
    hande dw ? 

.code 
.startup 
    ;enter the name of the file 
    lea dx,max1 
    mov ah,0ah 
    int 21h 

    ;delete the file 
    mov ah,41h 
    lea dx, inp1 
    int 21h 
.exit 
end 
+2

你'inp1'獲得該字符包括最終cariiage回報。假設您要返回的文件的名稱不包含任何回車符。 – Michael

+0

使用好老的「debug.com」,跟蹤第一個int21h後面的程序,看看輸入了什麼......它不是真的int 21/41h期望的;-) – Tommylee2k

+0

這是刪除,不會刪除(標題,代碼評論) –

回答

5

正如Michael所說的那樣,您按下的[ENTER]也存儲在輸入緩衝區內。你必須用0來取代它之前,你可以調用INT 21/41

start: 
     ;enter the name of the file 
     lea dx,max1 
     mov ah,0ah 
     int 21h 

     mov si,offset act1 ; inc si is coming before cmp, so start ahead 
    lookup: 
     inc si 
     cmp byte ptr [si],0Dh 
     jnz lookup 
     mov byte ptr[si],0 

     ;delete the file 
     mov ah,41h 
     lea dx, inp1 
     int 21h 

提示:如果你「INC SI」後的比較,你會破壞它的標誌設置。所以我在比較之前移動了inc si,並且SI必須在緩衝區之前加載一個字節。 ps:查找很簡單(也很危險,它在內存中找到任何0x0D之前沒有停止),我很確定有一個x86 loopup指令somwhere :-)

as(again)Michael said (再次),輸入緩衝區的第二個字節會告訴輸入的字符串是多長時間(以及0x0d是什麼,因爲它是輸入的最後一個字母)。所以沒有必要尋找它,它在[INP1 + ACT1]

start: 
    lea dx,max1    ;enter the name of the file 
    mov ah,0ah 
    int 21h 

pick: 
    mov si,offset inp1  ; get offset of entered string 
    xor bh,bh 
    mov bl,[act1]   ; and it's len (the CR should be there) 
    mov byte ptr [bx+si],0 ; replace it with a 0 

    mov ah,41h    ;delete the file 
    lea dx, inp1 
    int 21h 
+0

謝謝,我明白了你的觀點,併發揮了作用。 –

+1

'act1'將包含讀取的字符數,不包括回車符。所以你不需要搜索CR角色,因爲你知道它所在的位置。 – Michael

+0

啊,好點;沒有注意到:P – Tommylee2k

相關問題