我正在尝试编写一个8086汇编程序来连接两个给定的字符串.为了做到这一点,我使用了" REP MOVSB "指令,但程序运行不正常.所以我编写了一个应该静态连接两个字符串的程序,但似乎" REP MOVSB "根本不影响字符串.这是我为测试编写的代码部分:
data segment
string1 db "Lotfi", 0
string2 db "Ali ", 0
data ends
code segment
ASSUME CS: code, DS: data
start:
cld
mov ax , data
mov DS , ax
mov SI , offset string1
mov DI , offset string2
add DI , 3 ; Adding the length of destination string to the DI
mov cx , 5
rep movsb ; This should concat two strings
; Printing the result character by character on the console
mov SI , offset string2
l: lodsb ; Printing loop
mov dl, al
mov ah, 2h
int 21h
jmp l
hlt
code ends
end start
代码的结果如下:
Ali ü,Z0???... (And so)
我的代码出了什么问题?坦
movsb从DS:SI移动到ES:DI.您已加载DS但不加载ES寄存器.
您只需添加一行:
cld
mov ax , data
mov DS , ax
mov ES , ax ; here!
Run Code Online (Sandbox Code Playgroud)