繁体   English   中英

从命令提示符读取字符并在8086程序集中使用它们作为路径名

[英]Reading characters from command prompt and using them for path-name in 8086 assembly

我的程序有目的:从命令行读取符号并将它们用作到另一个目录的完整路径名。 如果不是从命令行输入符号而是将缓冲区定义为“P:\\ test \\”,则该程序有效,因此问题在于读取字符。 但是,我尝试使用以下方法打印出我的缓冲区:啊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更改驱动器Int 21h/AH=3Bh

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM