-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcproj.asm
321 lines (261 loc) · 5.24 KB
/
cproj.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
.model small
.stack 100h
.386
.data
prompt db "Enter a string: $"
hbd db 10,13,"Enter 1 for binary, 2 for decimal and 3 for hexadecimal: $"
string db 100 dup(0)
dbin db 10,13,"The frequency in Binary is: $"
dhex db 10,13,"The frequency in Hexadecimal is: $"
ddec db 10,13,"The frequency in Decimal is: $"
num db 127 dup(00)
.code
frequency proc
push cx
mov di, offset num
add di, bx
mov ax, [di]
inc ax
mov [di], ax
pop cx
ret
frequency endp
clearfreq proc
push cx
mov cx, 127
mov di, offset num
clearfreq_l1:
mov ax, 0
mov [di], ax
inc di
loop clearfreq_l1;
pop cx
ret
clearfreq endp
decout proc ;to display in decimal
push cx
push ax
push dx
push bx
mov cx,0
xor ax, ax
mov al, dl
xor dx, dx
l1:
cmp ax, 0
je p1
mov bx, 10
div bx
push dx
inc cx
xor dx, dx
jmp l1
p1:
cmp cx, 0
je decout_e
pop dx
add dx, 48
mov ah, 02h
int 21h
dec cx
jmp p1
decout_e:
mov dl, " "
mov ah, 02
int 21h
pop cx
pop dx
pop bx
pop ax
ret
decout endp
binout proc ;for binary output
push cx
push ax
push dx
push bx
mov cx,0
aga:
mov bx,2d
mov dx,0000
div bx
inc cx
push dx
cmp ax,0000
jne aga
mov ah,02
disp:
pop dx
add dl,30h
int 21h
dec cx
jnz disp
pop cx
pop dx
pop bx
pop ax
ret
binout endp
hexout proc ;for binary output
push cx
mov cx, 2
again1:
rol bl, 4
mov dl, bl
and dl, 0fh
cmp dl, 9h
jbe alpha
add dl, 37h
mov ah, 02
int 21h
jmp e
alpha:
add dl, 30h
mov ah, 02
int 21h
e:
dec cx
jnz again1
pop cx
ret
hexout endp
.code
main proc
mov ax, @data
mov ds, ax
call clearfreq
mov dx, offset prompt ;printing "Enter a string: "
mov ah,09h
int 21h
mov si, offset string
input1:
mov ah,01h
int 21h
mov [si],al
cmp al, 13
je displaystr ;taking input till the $
inc si
jmp input1
displaystr:
mov dx, offset hbd ;printing "Enter b for binary, d for decimal and h for hexadecimal: $"
mov ah,09h
int 21h
mov ah,01h ;checking whether to display in binary, hexadecimal or decimal
int 21h
cmp al,"1"
je display_binary
cmp al,"3"
je display_hexadecimal
display_decimal:
mov dx, offset ddec ;"The frequency in decimal is: $"
mov ah,09h
int 21h
mov si, offset string
lld:
xor bx, bx
mov bl,[si]
cmp bl,13
je ched
call frequency
inc si
jmp lld
ched:
mov si, offset string
dec_print_loop:
mov bl, [si]
cmp bl, 13
je terminate
mov dl, [si]
mov ah, 02h
int 21h
mov dl, ":"
mov ah, 02h
int 21h
xor bx, bx
xor di, di
xor dx, dx
mov bl, [si]
mov di, offset num
add di, bx
mov dl, [di]
call decout
inc si
jmp dec_print_loop
display_binary:
mov dx, offset dbin ;"The frequency in Binary is: $"
mov ah,09h
int 21h
mov si, offset string
llb:
xor bx, bx
mov bl,[si]
cmp bl,13
je cheb
call frequency
inc si
jmp llb
cheb:
mov si, offset string
bin_print_loop:
mov bl, [si]
cmp bl, 13
je terminate
mov dl, [si]
mov ah, 02h
int 21h
mov dl, ":"
mov ah, 02h
int 21h
xor bx, bx
xor di, di
xor dx, dx
mov bl, [si]
mov di, offset num
add di, bx
mov dl, [di]
xor ax, ax
mov al, dl
call binout
inc si
jmp bin_print_loop
display_hexadecimal:
mov dx, offset dhex ;"The frequency in hexadecimal is: $"
mov ah,09h
int 21h
mov si, offset string
llh:
xor bx, bx
mov bl,[si]
cmp bl,13
je cheh
call frequency
inc si
jmp llh
cheh:
mov si, offset string
hex_print_loop:
mov bl, [si]
cmp bl, 13
je terminate
mov dl, [si]
mov ah, 02h
int 21h
mov dl, ":"
mov ah, 02h
int 21h
xor bx, bx
xor di, di
xor dx, dx
mov bl, [si]
mov di, offset num
add di, bx
mov dl, [di]
mov bl, dl
call hexout
inc si
jmp hex_print_loop
terminate:
mov ah,4ch
int 21h
main endp
end main