forked from M-Ammar1112/x86-Assembly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_arrays.ASM
112 lines (84 loc) · 1.69 KB
/
merge_arrays.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
.model small
.stack 100h
.data
N1 equ 5
N2 equ 5
N3 equ N1+N2
A db 1, 3, 5, 7, 9
B db 2, 4, 6, 8, 10
C db N3 dup(0)
.code
main proc
mov ax, @data
mov ds, ax
mov si, offset A
mov di, offset B
mov bx, offset C
mov cx, N1
mov dx, N2
merging_array:
cmp cx, 0
je copy_rem_b
cmp dx, 0
je copy_rem_a
mov al, [si]
mov bl, [di]
cmp al, bl
jle copy_a
jmp copy_b
copy_a:
mov [bx], al
inc si
dec cx
jmp consecutive_iteration
copy_b:
mov [bx], bl
inc di
dec dx
jmp consecutive_iteration
copy_rem_a:
mov al, [si]
mov [bx], al
inc si
jmp consecutive_iteration
copy_rem_b:
mov al, [di]
mov [bx], al
inc di
jmp consecutive_iteration
consecutive_iteration:
inc bx
loop merging_array
mov si, offset A
mov cx, N1
call print_array
mov si, offset B
mov cx, N2
call print_array
mov si, offset C
mov cx, N3
call print_array
mov ax, 4C00h
int 21h
main endp
print_array proc
mov dl, '['
mov ah, 2
int 21h
print:
mov al, [si]
mov dl, [si]
add dl, 30h
mov ah, 2
int 21h
inc si
loop print
mov dl, ']'
mov ah, 2
int 21h
mov dl, ','
mov ah, 2
int 21h
ret
print_array endp
end main