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)
countA1 dw 0
countA2 dw 0
.code
main proc
sub EAX,EAX
mov ESI,OFFSET a1
mov EDI,OFFSET a2
mov EDX,OFFSET a3
call Merge
call Display
exit
main endp
jmp Endit
;=====================================================================
Merge proc
TheJump:
.WHILE countA1 < 7
mov ax,[ESI]
cmp ax,[EDI]
jl AddA1 ;Jump if less
jg AddA2 ;Jump if greater
.ENDW
;Executes after first array has finished
;=================================================================
.WHILE (countA2 < lengthof a2)
add countA2,1
mov ax,[EDI]
mov [EDX],ax
add EDI,2
add EDX,2
.ENDW
;=====================================================================
jmp EndJump
AddA1:
add countA1,1
mov ax,[ESI]
mov [EDX],ax
add ESI,2
add EDX,2
jmp TheJump
AddA2:
add countA2,1
mov ax,[EDI]
mov [EDX],ax
add EDI,2
add EDX,2
jmp TheJump
EndJump:
ret
Merge endp
;==================================================================
Display proc
mov ECX,lengthof a3 ;Set loop times
mov EDX,offset a3
DisplayLoop:
mov ax,[EDX]
add EDX,2
call writedec
call crlf
loop DisplayLoop
ret
Display endp
;===================================================================
Endit:
end main
Comments
Post a Comment