問題描述
為什麼這個彙編代碼不刪除擴展名為“.lnk”的文件? (Why doesn't this assembly code delete the file with ".lnk" extension?)
我正在嘗試使用程序集 8086 架構刪除擴展名為“.lnk”的文件。當我在“mov si, dx”之後寫“jmp DELETE”並跳過內部、back1、back2、back3 部分時,我的代碼會刪除所有文件,但是當它逐個字符檢查它是否具有 .lnk 擴展名時,它不會t 刪除其中任何一個,甚至不刪除擴展名為 .lnk 的文件。為什麼會這樣?
.MODEL SMALL
.STACK 100H
.DATA
FILE DB "*", 0
DTA DB 128H DUP(?)
FILENAME DB 50 DUP(?)
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
;SET DTA
MOV DX,OFFSET DTA
MOV AH,1AH
INT 21H
;FIRST SEARCH
MOV DX,OFFSET FILE
MOV CX,0
MOV AH,4EH
INT 21H
JC QUIT
OUTER_LOOP:
;DELETE
LEA DX,DTA+30
mov si, dx
inner:
cmp [si], 0
je back1
inc si
jmp inner
back1:
dec si
cmp [si],'K'
je back2
jmp NEXT
back2:
dec si
cmp [si],'N'
je back3
jmp NEXT
back3:
dec si
cmp [si], 'L'
delete:
LEA DX,DTA+30
MOV AH,41H
INT 21H
;INITIATE NEXT SEARCH
NEXT:
MOV DX,OFFSET FILE
MOV CX,0
MOV AH,4FH
INT 21H
JC QUIT
JMP OUTER_LOOP
QUIT:
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
參考解法
方法 1:
These points might interest you:
Change your filemask to
*.*
Why do you set up such a large DTA?.
DTA 44 dup(?)
Always write
cmp byte ptr [si], ...
Don't stop comparing after the 3 characters. Add a fourth compare to see if the point is present. Then you'll know that LNK is indeed a file extension.
Your 4Fh DOS call doesn't need the CX and DX parameters.
You don't interpret the result from
cmp [si], 'L'
(by harmione 、Sep Roland)