汇编连接两个字符串

assembly concatenate two strings

我想连接两个字符串,但在我的输出中没有得到最终的连接字符串,而是一行奇怪的字符和空格,也许有人可以帮我一下。我想将结果保存在 s3 中。这是代码

DATA SEGMENT
    STR1 DB "ENTER FIRST STRING HERE ->$"
    STR2 DB "ENTER SECOND STRING HERE ->$"
    STR3 DB "CONCATEnatedD STRING :->$"
    STR11 DB "FIRST STRING : ->$"
    STR22 DB "SECOND STRING: ->$"

    s1 DB 20 DUP("$")
    s2 DB 20 DUP("$")
    s3 db 40 dup(?)
    NEWLINE DB 10,13,"$"

DATA ENDS

CODE SEGMENT

    ASSUME DS:DATA,CS:CODE
START:

    MOV AX,DATA
    MOV DS,AX


lea dx,str1
mov ah,09h
int 21h

lea si,s1

l1: mov ah,01h
int 21h

mov [si],al
inc si
cmp al,31h
jne l1

dec si

lea dx,str2
mov ah,09h
int 21h

lea di,s2

l2: mov ah,01h
int 21h

mov [di],al
inc di
cmp al,32h
jnz l2

lea si,s3
lea di,s1


lea si,s3
lea di,s1
l3: mov al,[di]
mov [si],al
inc si
inc di
cmp al,31h
jnz l3

dec si

lea di,s2

l4: mov al,[di]
mov [si],al
inc si
inc di
cmp al,32h
jnz l4

lea dx,str3
mov ah,09h
int 21h

l5: mov dl,[si]
cmp dl,32h
jz l6
mov ah,02h
int 21h
inc si
jmp l5


l6:MOV AH,4CH
    INT 21H


CODE ENDS
END START

我已经找到解决办法了,希望它是一个好的,没有任何错误: 数据段 味精数据库 0Dh,0Ah,"String1: $" msg2 db 0Dh,0Ah,"String2: $" 转速分贝 0Dh,0Ah,"Result: $"

buffer label byte  
buffer2 label byte
str_maxlen db 255
str_length db 0

str_string db 255 dup(0)
str_string2 db 255 dup(0)
result db 255 dup('$')
num db 0
data ends

code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax

lea dx,msg
mov ah,09h
int 21h

lea dx,buffer
mov ah,0Ah
int 21h

mov cl,str_length
mov bh,cl
mov ch,0
lea si,str_string
lea di,result

op1:    mov bl,[si]
mov [di],bl
inc di
inc si
loop op1

mov cl,bh
op3:    dec si
loop op3

lea dx,msg2
mov ah,09h
int 21h

lea dx,buffer2
mov ah,0Ah
int 21h
mov cl,str_length

lea si,str_string
mov cl,str_length

mov ax,0
op2:    mov al,[si]
mov [di],al
inc di
inc si
loop op2

lea dx,rev
mov ah,09h
int 21h

lea dx,result
mov ah,09h
int 21h

mov ah,4Ch
int 21h
code ends

end start

在您的第一个代码中,您必须将 si 设置为指向标签 l5: 之前的字符串 s3 的开头(因为 si 在循环 l4: 之后指向 s3 的末尾) :

.
.
.
lea dx,str3
mov ah,09h
int 21h

lea si,s3          ;◄■■■■■■■■■■■  
l5: mov dl,[si]
cmp dl,32h
jz l6
.
.
.