Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 显示字符串的汇编代码_String_Assembly_Input_Dos - Fatal编程技术网

String 显示字符串的汇编代码

String 显示字符串的汇编代码,string,assembly,input,dos,String,Assembly,Input,Dos,我有一段汇编代码来接受一个字符串并显示该字符串 我的问题是,当我们使用buff存储用户输入时,我无法确定名称在name1中的存储方式 我知道 buff label byte maxchar db 50 readchar db 0 name1 db 48 dup(0) 与此有关。但我无法理解工作原理 .model small .stack .data buff label byte maxchar db 50 readchar db 0 name1 db 48 d

我有一段汇编代码来接受一个字符串并显示该字符串

我的问题是,当我们使用buff存储用户输入时,我无法确定名称在
name1
中的存储方式

我知道

buff label byte
maxchar db 50
readchar db 0
name1 db 48 dup(0)
与此有关。但我无法理解工作原理

.model small
.stack
.data
    buff label byte
    maxchar db 50
    readchar db 0
    name1 db 48 dup(0)
    m1 db 10,13,"enter name: $"
    m2 db 10,13,"your name is: $"
.code
    mov ax, @data
    mov ds, ax
    lea dx, m1
    mov ah, 09
    int 21h
    lea dx, buff
    mov ah, 10
    int 21h


    mov ah,0
    mov al, readchar
    add ax, 2
    mov si, al
    mov buff[si],24H ;ascii code for $ to terminate string
    lea dx, m2
    mov ah, 9
    int 21h
    lea dx, name1
    mov ah, 09
    int 21h

    mov ah, 4ch
    int 21h
end
请帮忙


谢谢。

使用DOS函数0x0a(或代码中的十进制10)读取输入,该函数执行缓冲输入。DS:DX参数指向具有以下格式的缓冲区,该缓冲区位于程序中标记为
buff
(或等效为
maxchar
)的位置:

 offset    meaning
 ------  -------------
    0      Number of bytes available for the input data (starting at offset 2)
    1      A location for DOS to put the number of characters read into the buffer
    2      A buffer of bytes that can hold the number of characters specified in 
           offset 0

因此,在代码中,DS:DX指向
buff
,这表示最多可以在
name1
处将50个字符放入缓冲区。看起来代码有一个潜在的问题,因为缓冲区中只有48个字节,但数据结构表明有50个字节。因此,输入可能会覆盖
m1
的前两个字节。现在,汇编程序——特别是旧的汇编程序——以执行各种各样的技巧来节省空间而闻名
m1
在调用DOS函数0x0a后没有使用,因此这可能是有意的(但如果是这样,我不确定为什么没有提供更多的
m1
)。我猜这是无意的,这个bug从来没有表现出任何明显的迹象。

而且,它应该是
mov-si,ax
,而不是
mov-si,al
。只有
movsx
movzx
可以将8位寄存器值移动到16位寄存器,
mov
不能。