Assembly 在MSDOS中,要求此人输入现有文件名,然后将其删除

Assembly 在MSDOS中,要求此人输入现有文件名,然后将其删除,assembly,masm,dos,dosbox,x86-16,Assembly,Masm,Dos,Dosbox,X86 16,我写了下面的程序,但它不工作。我将文件名输入为dur.txt。它返回AX=4C03。为什么它不起作用?我如何纠正它 .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 f

我写了下面的程序,但它不工作。我将文件名输入为
dur.txt
。它返回AX=4C03。为什么它不起作用?我如何纠正它

.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

正如Michael所说,您按下的[ENTER]键也存储在输入缓冲区中。在调用int 21/41之前,必须将其替换为0

    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循环指令somwhere:-)

正如Michael(再次)正确指出的那样,输入缓冲区的第二个字节将显示输入的字符串的长度(以及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

您在
inp1
中获得的字符包括最终的cariiage报税表。假设您试图返回的文件名不包含任何回车符。请使用旧的“debug.com”,跟踪程序直到第一个int21h之后,然后查看输入的内容。。。这并不是int 21/41h所期望的;-)它是delete,而不是delate(title,code comment)
act1
将包含读取的字符数,不包括回车符。因此,没有必要搜索CR角色,因为您知道它的位置。