hello
I am trying to make a program to interlace 2 vectors in assembler and I have a problem
I will probably have more until the end
but here is the deal
so I now have 2 sorted vectors a and b and I want to put their elements sorted into the vector c
so, to write a value to the vecor c I use
mov c,bx
which of course is worng
so how should I do it?
I am also pasting the full source here so you can maby point out the thousands of other mistakes I undoubtely have:
thank you in advance
I am trying to make a program to interlace 2 vectors in assembler and I have a problem
I will probably have more until the end
but here is the deal
a db '13579'
la equ $-a
b db '2468'
lb equ $-b
c db (la+lb) dup(?)
so I now have 2 sorted vectors a and b and I want to put their elements sorted into the vector c
so, to write a value to the vecor c I use
mov c,bx
which of course is worng
so how should I do it?
I am also pasting the full source here so you can maby point out the thousands of other mistakes I undoubtely have:
.model small
.stack 100h
.data
a db '13579'
la equ $-a
b db '2468'
lb equ $-b
c db (la+lb) dup(?)
.code
mov dx,@data
mov ds,dx
xor si,si
xor di,di
xor cx,cx
cicluprincipal:
mov al,la
mov ah,0
mov bl,lb
mov bh,0
cmp ax,bx
jge maimareegal
mov c,ax
inc cx
mov dl,la
mov dh,0
cmp di,dx
jg tiparb
inc si
jmp cicluprincipal
maimareegal:
mov c,bx
inc cx
mov dl,la
mov dh,0
cmp di,dx
jg tipara
inc di
jmp cicluprincipal
tiparb: ;tipareste tot ce e in b
inc di
mov bl,b
mov bh,0
mov c,bx
cmp cx,bx
jg exit
inc cx
jmp tiparb
tipara: ;tipareste tot ce e in a
inc si
mov bl,a
mov bh,0
mov c,bx
cmp cx,bx
jg exit
inc cx
jmp tipara
mov ax,4ch
int 21h
end
thank you in advance
para,
Look for a bubble sort routine. Otherwise you will be reinventing the wheel. The code below supposes a fictional bubble sort. Ratch
Look for a bubble sort routine. Otherwise you will be reinventing the wheel. The code below supposes a fictional bubble sort. Ratch
EXTERN BUBBLE_SORT:DWORD
.DATA?
.DATA
a BYTE '12579'
b BYTE '2468'
.CODE
START:
; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл
PUSH OFFSET a
PUSH (SIZEOF a + SIZEOF b)
CALL BUBBLE_SORT
Although, if the vectors you're "interlacing" (or "merging") are already sorted, you can just use a merge algorithm like what's used in merge sort.
Perhaps keeping integer values as strings is overkill/a bad idea?
Can't you work with actual integer values and convert them to strings only for display purposes and on demand?
Can't you work with actual integer values and convert them to strings only for display purposes and on demand?