Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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 操纵程序集x86中的字符串(mov和打印到屏幕)_String_Assembly_Tasm - Fatal编程技术网

String 操纵程序集x86中的字符串(mov和打印到屏幕)

String 操纵程序集x86中的字符串(mov和打印到屏幕),string,assembly,tasm,String,Assembly,Tasm,我正在做一个更大的项目,但我被字符串操作卡住了。我的汇编文件包含数学协处理器操作(它以“FINIT”启动协处理器),但我认为它根本不应该有任何干扰。 基本上,我有一些字符串,每个长度为50字节: $s db 50 dup (?), '$' _cte_14 db "hello world", '$', 39 dup (?) 我需要将存储在变量“\u cte\u 14”中的值分配给变量“$s” 我尝试使用寄存器临时存储该值,如下所示: mov cx, _cte_14 mov $s, cx 但我得

我正在做一个更大的项目,但我被字符串操作卡住了。我的汇编文件包含数学协处理器操作(它以“FINIT”启动协处理器),但我认为它根本不应该有任何干扰。 基本上,我有一些字符串,每个长度为50字节:

$s db 50 dup (?), '$'
_cte_14 db "hello world", '$', 39 dup (?)
我需要将存储在变量“\u cte\u 14”中的值分配给变量“$s” 我尝试使用寄存器临时存储该值,如下所示:

mov cx, _cte_14
mov $s, cx
但我得到了“操作数类型不匹配”错误

因为我知道AX、BX、CX、DX寄存器只包含16位,所以我想可能需要使用第一个字符串的内存地址,所以我尝试:

mov bx, offset _cte_14
mov $s, bx
但同样的错误也出现了

我正在使用TASM为x86处理器编译。实现这一目标的正确方法是什么


提前非常感谢。

复制循环中字符的示例:

s db 51 dup ('$')
_cte_14 db "hello world"
len = ($ - _cte_14)    ; (current location - offset _cte_14)
40 dup ('$')

mov si, offset _cte_14 ; get source offset
mov di, offset s       ; get destination offset
mov cl, len            ; length of the string
P1:
mov al, [si]           ; get byte from DS:SI
mov [di], al           ; store byte to DS:DI
dec cl                 ; decrease counter, set zero flag if zero
jnz P1                 ; jump if zero flag is not set
--与重复指令前缀一起使用字符串指令的变化:

mov si, offset _cte_14
mov di, offset s
mov cx, len ; length of the string
cld         ; clear direction flag
rep movsb   ; copy from DS:SI to ES:DI, increase SI+DI, decrease CX, repeat CX times

您需要复制循环中的字符,或使用字符串移动(
movsb
)指令。回答中的一些注释会有用,告诉您提供/修复的内容谢谢!!不过我还是有点困惑。。。因为您对my.data声明做了一些更改,所以我不完全理解您的代码。我不确定“len”如何包含源字符串的长度。另外,不确定
40 dup(“$”)
的作用。我尝试了您的代码,但没有更改.DATA段并手动插入源代码长度:
mov cl,12;“hello world$”的长度
然后添加这个来打印$s的内容:
mov DX,偏移量$s mov AH,9 int 21h
,但我得到的只是首字母“h”和一堆空格。别管它了!刚刚发现遗漏了什么:您的循环代码非常完美,只遗漏了
inc-si
inc-di
。就在12月1日之前添加了这一点,效果非常好。谢谢