简体   繁体   English

两个弦组件8086的插入元素

[英]intercalate elements of two strings assembly 8086

I have a little problem with my program. 我的程序有一点问题。 I have to intercalate the elements of two strings,so if i have 我必须插入两个字符串的元素,所以如果我有

S1: 1, 3, 5, 7 S1:1、3、5、7
S2: 2, 6, 9, 4 S2:2、6、9、4

it will result D: 1, 2, 3, 6, 5, 9, 7, 4. 结果为D:1、2、3、6、5、9、7、4。

This is what i did so far, and i have no idea how to fix it, any help please? 这是我到目前为止所做的,我不知道如何解决,请帮忙吗?

assume cs:code, ds:data

data segment
s1 db '1357'
s2 db '2694'
l1 EQU ($-s1)
l2 EQU ($-s2)
d db (l1+l2) dup (?)
data ends

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

mov si,offset s1
mov cx,l1
mov bx, 0
frst:
    mov ax,[si]
    mov [di]+[bx],ax
    inc si
    add bx,2
loop frst
mov si, offset s2
mov cx,l2
mov bx,1

scnd:
    mov ax,[si]
    mov [di]+[bx],ax
    inc si
    add bx,2
loop scnd

mov ax,4c00h
int 21h
code ends
end start

There are several mistakes in the code, firstly 代码中有几个错误,首先

s1 db '1357'
s2 db '2694'
l1 EQU ($-s1)
l2 EQU ($-s2)

gets the length of s1 wrong, it should be 得出s1的长度错误,应该是

s1 db '1357'
l1 EQU ($-s1)
s2 db '2694'
l2 EQU ($-s2)

Secondly, di is used but not initialised, insert 其次,使用di但未初始化,插入

mov di, offset d

before the first loop. 在第一个循环之前。 Next, the data arrays are byte values defined by db , but you are loading and storing ax register. 接下来,数据数组是db定义的byte值,但是您正在加载和存储ax寄存器。 This should be the al register, as 这应该是al寄存器,因为

mov al,[si]
mov [di]+[bx],al

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM