I need to merge two arrays that are already sorted into another larger array, also in order. I can't use a sort. It assembles fine but won't display anything.
This is what I have so far. I'm new to this so go easy if its not the best.
include irvine32.inc
Title MergeArrays
.data
a1 dw 1,3,4,7,9,15,17
a2 dw 2,6,8,10,11,14,18,19
a3 dw 15 dup(0)
.code
main proc
sub EAX,EAX
mov ESI,OFFSET a1
mov EDI,OFFSET a2
mov EDX,OFFSET a3
mov ECX,lengthof a3 ;Set loop times
call Merge
call Display
exit
main endp
jmp Endit
;=====================================================================
Merge proc
TheLoop:
TheJump:
mov ax,[ESI]
cmp ax,[EDI]
jl AddA1 ;Jump if less
jg AddA2 ;Jump if greater
Loop TheLoop
AddA1:
mov ax,[ESI]
mov [EDX],ax
inc ESI
inc EDX
jmp TheJump
AddA2:
mov ax,[EDI]
mov [EDX],ax
inc EDI
inc EDX
jmp TheJump
Merge endp
;==================================================================
Display proc
mov ECX,lengthof a3 ;Set loop times
mov EDX,OFFSET a3
DisplayLoop:
mov ax,[EDX]
call writedec
call crlf
inc EDX
loop DisplayLoop
Display endp
;===================================================================
Endit:
end main
What happens when TheLoop
is down to zero? ecx
becomes negative, exits the loop and then KEEPS going to the next instruction which happens to be AddA1
then back to TheJump
then to either AddA1
or AddA2
, it is an infinite loop. You need to add something after Loop TheLoop
and before AddA1
to exit the proc.
You don't really need a debugger, just something that will print passed values for debugging.