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
S2: 2, 6, 9, 4
it will result 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 db '1357'
l1 EQU ($-s1)
s2 db '2694'
l2 EQU ($-s2)
Secondly, di
is used but not initialised, insert
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. This should be the al
register, as
mov al,[si]
mov [di]+[bx],al
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.