在 DOS 中设置 DS 并使用 AH = 0Ah

Setting DS and using AH = 0Ah in DOS

所以我试图在 DOS 程序集中获取用户输入,但我似乎无法理解如何以某种方式设置 DS 和 DX,以便缓冲输入中断写入正确的位置。这是我的主文件的代码:

BITS 16
org 0x100

Start:

; SNIP

mov dx, Name
call GetString

; SNIP

Exit:
mov ax, 0x4c00
int 0x21

Name:
        db 33
        db 0
        times 255 db 0

这是我的 GetString 过程,它来自另一个文件。我打算让它在调用函数之前设置 DX,然后让 DX 指向实际字符串的开头:

GetString:
push ax
push bx
; syscall
mov ax, 0x0a
int 0x21
mov bx, dx ; move buffer to adressing register
inc bx ; get number of chars read 
movzx si, [bx] ; put bx's value (numbers of chars read) into si
inc bx ; get actual string buffer
add si, bx ; number of chars read + buffer = last byte
mov byte [si], '$' ; $ terminate
mov dx, bx
pop bx
pop ax
ret

我似乎不明白为什么它不起作用。我应该将 DS 设置为什么吗?如果是,应该设置什么?

GetString你有

mov ax, 0x0a
int 0x21

这会加载 ah00al0ah)并调用中断 21h 函数 00h 即 "terminate program".

如果你想调用函数0ah "buffered STDIN input"你需要

mov ah, 0x0a
int 0x21

连同 DS:DX 指向已初始化的缓冲区,正如您所做的那样。