Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.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
Assembly 在TASM x86程序集中读取字符串_Assembly - Fatal编程技术网

Assembly 在TASM x86程序集中读取字符串

Assembly 在TASM x86程序集中读取字符串,assembly,Assembly,我正在尝试从TASM程序集中的用户处读取字符串,我知道我需要一个缓冲区来保存输入、最大长度和实际长度,但我似乎忘记了如何准确地声明缓冲区 我的尝试是这样的 Buffer db 80 ;max length db ? ;actual length db 80 dup(0);i think here is my problem but can't remember the right format 提前感谢DB(define byte)指令用于分配字节大小的内存块。D

我正在尝试从TASM程序集中的用户处读取字符串,我知道我需要一个缓冲区来保存输入、最大长度和实际长度,但我似乎忘记了如何准确地声明缓冲区

我的尝试是这样的

Buffer db 80 ;max length
       db ?  ;actual length
       db 80 dup(0);i think here is my problem but can't remember the right format
提前感谢

DB(define byte)指令用于分配字节大小的内存块。DB后面的部分指定应放入已分配内存的值。例如,如果要定义一个值为65的单字节内存,可以使用以下指令

SingleByte   DB  65        ; allocate a single byte and write 65 into the byte
TenBytes     DB  10 DUP(65); allocate 10 bytes and write 65 into each byte
DUP(duplicate)指令用于复制一系列字符。要复制的字符系列在DUP后面的括号内指定。DUP之前的数字指定应复制字符序列的次数。例如,如果要定义一个10字节的内存块,其中每个字节的值为65,则可以使用以下指令

SingleByte   DB  65        ; allocate a single byte and write 65 into the byte
TenBytes     DB  10 DUP(65); allocate 10 bytes and write 65 into each byte
在您的情况下,您不关心缓冲区中每个字节最初存储了哪些值,因此可以使用
作为要复制的字节。如果要将每个字节初始化为零,可以将
替换为
0

Buffer       DB  80 DUP(?) ; set aside 80 bytes without assigning them any values
缓冲区的最大长度和实际长度应使用单独的变量进行管理。总之,你可能想要以下性质的东西

Buffer       DB  80 DUP(0) ; 80-byte buffer initialized to all zeros
BufferMaxLen DB  80        ; maximum length of Buffer
BufferLen    DB  0         ; actual length of Buffer