我的程序有一个目的:从命令行读取符号,并将它们用作通往另一个目录的完整路径名。如果不是从命令行输入符号,而是将缓冲区定义为"P:\test\",则该程序可以工作,因此问题在于读取字符。然而,我试图通过使用:ah 02h int 21h(单字符输出)打印出我的缓冲区,它正确地输出了它。
.model small
.stack 100h
.data
dir db 255 dup (0)
.code
start:
mov dx, @data
mov ds, dx
xor cx, cx
mov cl, es:[80h]
mov si, 0082h ;reading from command prompt 0082h because first one is space
xor bx, bx
l1:
mov al, es:[si+bx] ;filling buffer
mov ds:[dir+bx], al
inc bx
loop l1
mov dx, offset dir ;going to directory
mov ah, 3Bh
int 21h
mov ah, 4ch
mov al, 0
int 21h
end start
在命令行的末尾始终存在一个0Dh
。所以es:[80h]
中的值(命令行中的字符数)太大了一个。此外,Int 21h/AH=3Bh
的路径末尾必须无效("ASCIZ"的意思是:ASCII字符加零)。
这个应该有效:
.model small
.stack 1000h ; Don't skimp on stack.
.data
dir db 255 dup (0)
.code
start:
mov dx, @data
mov ds, dx
xor cx, cx
mov cl, es:[80h]
dec cl ; Without the last character (0Dh)
mov si, 0082h ; reading from command prompt 0082h because first one is space
xor bx, bx
l1:
mov al, es:[si+bx] ; filling buffer
mov ds:[dir+bx], al
inc bx
loop l1
mov byte ptr [dir+bx], 0 ; Terminator
mov dx, offset dir ; going to directory
mov ah, 3Bh
int 21h
mov ax, 4C00h ; Exit with 0
int 21h
end start
您认为不能用Int 21h/AH=3Bh
更改驱动器号吗?