-
Notifications
You must be signed in to change notification settings - Fork 1
/
sort.asm
179 lines (150 loc) · 1.88 KB
/
sort.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
;ENTER YOUR INPUTS IN 4 BIT FORMAT(eg. 0030)
section .text
input:
mov eax,3
mov ebx,0
int 0x80
ret
output:
mov eax,4
mov ebx,1
int 0x80
ret
convert2d:
sub cl,30h
sub ch,30h
mov eax,0
mov al,cl
mov bl,10
mul bl
add al,ch
ret
convertbin:
call convert2d
shr ecx,16
sub cl,30h
sub ch,30h
mov bx,10
mul bl
add al,cl
mul bx
mov dx,0
mov dl,ch
add ax,dx
ret
global _start
_start:
mov ecx,inpno
mov edx,linpno
call output
mov ecx,num
mov edx,2
call input
mov ecx,temp
mov edx,1
call input
mov ecx,0
mov cx,word[num]
call convert2d
mov byte[no],al
mov byte[noi],al
taking:
mov ecx,inpmsg
mov edx,linp
call output
mov ecx,num
mov edx,4
call input
mov ecx,temp
mov edx,1
call input
mov ecx,dword[num]
call convertbin
mov edx,0
sub byte[noi],1
mov dl,byte[noi]
mov word[binary+2*edx],ax
cmp dx,0
jne taking
mov ebp,0
sort:
mov esi,0
insort:
mov ax,word[binary+2*esi]
mov bx,word[binary+2*esi+2]
cmp ax,bx
jle continue
mov word[binary+2*esi],bx
mov word[binary+2*esi+2],ax
continue:
add esi,1
mov edx,0
mov dl,byte[no]
sub dl,1
cmp esi,edx
jne insort
add ebp,1
mov edx,0
mov dl,byte[no]
cmp ebp,edx
jne sort
printoutput:
mov ebp,0
mov ecx,entered
mov edx,1
call output
mov ecx,omsg
mov edx,lomsg
call output
break:
push 29h
mov ax,word[binary+2*ebp]
breaking:
mov bx,10
mov edx,0
div bx
add dl,30h
push dx
cmp ax,0
jne breaking
print:
mov ax,0
pop ax
printing:
mov byte[printdata],al
mov ecx,printdata
mov edx,1
call output
pop ax
cmp ax,29h
jne printing
mov ecx,space
mov edx,1
call output
add ebp,1
mov edx,0
mov dl,byte[no]
cmp edx,ebp
jne break
mov ecx,entered
mov edx,1
call output
mov eax,1
mov ebx,0
int 0x80
section .bss
binary resw 100
section .data
printdata db 0
temp db 0
entered db 10
space db 32
no db 0
noi db 0
num dd 0
inpno db "ENTER THE NUMBER OF INPUTS : ",32
linpno equ $-inpno
inpmsg db "ENTER THE INPUT(4 BIT BINARY) : ",32
linp equ $-inpmsg
omsg db "SORTED ARRAY : ",32
lomsg equ $-omsg