gpt4 book ai didi

assembly - 在 8086 中连接两个给定的字符串 + MOVSB 不起作用

转载 作者:行者123 更新时间:2023-12-01 22:33:58 24 4
gpt4 key购买 nike

我正在尝试编写一个 8086 汇编程序来连接两个给定的字符串。为此,我使用了“REP MOVSB”指令,但该程序运行不佳。所以我写了一个应该静态连接两个字符串的程序,但似乎“REP MOVSB”对字符串根本没有影响。这是我为测试编写的代码部分:

                                          data    segment    string1 db  "Lotfi", 0string2 db  "Ali ", 0     data endscode 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 string2l:  lodsb           ; Printing loop    mov dl, al    mov ah, 2h    int 21h    jmp l        hlt         code endsend start

代码的结果是这样的:

Ali             ü,Z0???... (And so)

我的代码有什么问题?

最佳答案

movsb 从 DS:SI 移动到 ES:DI。您已加载 DS 但未加载 ES 寄存器。

你只需要添加一行:

cld
mov ax , data
mov DS , ax
mov ES , ax ; here!

关于assembly - 在 8086 中连接两个给定的字符串 + MOVSB 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27589178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com