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

时间:2015-11-02 09:29:00

标签: assembly x86-16 tasm 16-bit dosbox

我的程序有用:从命令行读取符号并将它们用作到另一个目录的完整路径名。 如果不是从命令行输入符号而是将缓冲区定义为" 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

1 个答案:

答案 0 :(得分:2)

在命令行的末尾始终是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更改驱动器号?