-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.asm
606 lines (418 loc) · 16.2 KB
/
code.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
data segment
; tables
mixed_table db 100 dup(?) ; store letter and numbers
items_table db 100 dup (?) ; store only letter
numbers_table db 100 dup(?) ; store only numbers
; 10d = 0ah =\n ; 13d=0dh=\r
NewLine db 0ah,0dh, "$"
; messages menu
menu_msg1 db '(1) Select number of items and length of Names and Numbers',10,13,'$'
menu_msg2 db '(2) enter the items',10,13,'$'
menu_msg3 db '(3) show the items in the same sequnce',10,13,'$'
menu_msg4 db '(4) show the entered items classfied as names or numbers',10,13,'$'
menu_msg5 db '(5) display names',10,13,'$'
menu_msg6 db '(6) display numbers',10,13,'$'
menu_msg7 db '(7) exit',10,13,'$'
; messages in each option
O1_msg_numberOfItems db 'Enter number of items: $'
O1_msg_invalidNumberOfItems db 'message: wrong number of items!',10,13,'$'
O1_msg_lengthOfItems db 'Enter length of items: $'
O1_msg_invalidLengthOfItems db 'message: wrong length of items!',10,13,'$'
O2_msg_valuesForItime db 'Enter values for item: $'
O2_msg_notValid db 'message: wrong input! just digits(1-9) and lowercase',10,13,'$'
O3_msg_showItems db 'Displaying Items and numbers',10,13,'$'
O3_msg_no_entered_values db 'No entered values, back to order 2',10,13,'$'
O4_msg_showItems db 'Displaying words',10,13,'$'
O4_msg_showNums db 'Displaying numbers',10,13,'$'
O5_msg_showNames db 'Displaying words',10,13,'$'
O6_msg_showNums db 'Displaying Numbers',10,13,'$'
o7_msg_closing db 'thank you for using our program',10,13,'$'
enter_your_chose_msg db 'Enter your chose: $'
new_chose_msg db '==========================================================================',10,13,'$'
invalid_chose_msg db '--------------------------------------------------------------------------',10,13,'$'
; take from user (length and item)
length_of_items db ?
num_of_items db ?
data ends
stack segment
dw 16 dup (0)
stack ends
code segment
Main proc far
Assume SS:stack,CS:code,DS:data
mov ax,data
mov ds,ax
mainMenu:
mov dx, offset menu_msg1
mov ah,9 ;output of a string at DS:DX. String must be terminated by '$'
int 21h
mov dx,offset menu_msg2
mov ah,9
int 21h
mov dx,offset menu_msg3
mov ah,9
int 21h
mov dx,offset menu_msg4
mov ah,9
int 21h
mov dx,offset menu_msg5
mov ah,9
int 21h
mov dx,offset menu_msg6
mov ah,9
int 21h
mov dx,offset menu_msg7
mov ah,9
int 21h
mov dx,offset enter_your_chose_msg
mov ah,9
int 21h
Mov ah,1 ;taking order (from user) , ah,1 => store in al
int 21h
sub al, 30h
cmp al,1 ; if else , check al
je option1
cmp al,2
je option2
cmp al,3
je option3
cmp al,4
je option4
cmp al,5
je option5
cmp al,6
je option6
cmp al,7
je Close
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset new_chose_msg
mov ah,9
int 21h
jmp mainMenu ;if input not valid number
; --------------------------------------------- Option 1 ---------------------------------------------
option1:
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O1_msg_numberOfItems
mov ah, 9
int 21h
Mov ah,1 ;taking number of items
int 21h
sub al, 30h
cmp al, 1
jl invalidNumberOfItems ; if the value not between this
cmp al, 9
ja invalidNumberOfItems
Mov num_of_items,al ; store number of items to al
mov dx, offset NewLine
mov ah, 9
int 21h
;////////////
mov dx, offset O1_msg_lengthOfItems
mov ah, 9
int 21h
mov ah,1
int 21h
sub al,30h
cmp al, 1
jl invalidLengthOfItems
cmp al, 9
ja invalidLengthOfItems
mov length_of_items,al
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx,offset new_chose_msg
mov ah,9
int 21h
jmp mainMenu
;//////////////////////////// order 1 => if invalid number of items
invalidNumberOfItems:
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O1_msg_invalidNumberOfItems
mov ah, 9
int 21h
mov dx, offset invalid_chose_msg
mov ah,9
int 21h
jmp mainMenu
;//////////////////////////// order 1 => if invalid length of items
invalidLengthOfItems:
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O1_msg_invalidLengthOfItems
mov ah, 9
int 21h
mov dx, offset invalid_chose_msg
mov ah,9
int 21h
jmp mainMenu
; --------------------------------------------- Option 2 ---------------------------------------------
option2:
; check if no number of items entered
cmp num_of_items,0
je invalidNumberOfItems
cmp num_of_items, 1
jl invalidNumberOfItems
cmp num_of_items, 9
ja invalidNumberOfItems
; loop through number of items in that length and assign values
; distinguish bw numbers and chars
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O2_msg_valuesForItime
mov ah, 9
int 21h
mov dx, offset NewLine
mov ah, 9
int 21h
mov si,0
mov di,0
mov bx,0
mov cl,num_of_items
mov ch,0
assign_items: ; outerloop
push cx
mov cl,length_of_items
mov ch,0
assign_values:
mov ah,1 ; taking value
int 21h
; check if item is started with a digit -> store it to numbers_table, if not then lowercase to items_table
cmp al,30h
jl input_notValid
cmp al,39h
ja word_or_not_valid
mov numbers_table[bx],al
mov mixed_table[di],al
inc bx
inc di
jmp numbers_continue
word_or_not_valid:
cmp al,61h
jl input_notValid
cmp al,7ah
ja input_notValid
mov items_table[si],al
mov mixed_table[di],al
inc si
inc di
numbers_continue:
loop assign_values
; ////////////////////////////////
mov items_table[si],0ah,0dh
mov numbers_table[bx],0ah,0dh
inc si
inc bx
inc num_of_items
; ////////////////////////////////
mov dx, offset NewLine
mov ah, 9
int 21h
pop cx
loop assign_items
mov dx,offset new_chose_msg
mov ah,9
int 21h
jmp mainMenu
;////////////////////////////
input_notValid:
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O2_msg_notValid
mov ah, 9
int 21h
mov dx, offset invalid_chose_msg
mov ah,9
int 21h
jmp mainMenu
; --------------------------------------------- Option 3 ---------------------------------------------
option3:
cmp mixed_table[00],0
je no_entered_values
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O3_msg_showItems
mov ah, 9
int 21h
; print the items from table mixed
mov di,0
mov cl,num_of_items
mov ch,0
O3_print_items:
push cx ; num of items
mov cl,length_of_items
mov ch,0
O3_print_values:
mov dl,mixed_table[di]
Mov ah, 02h
int 21h
inc di
loop O3_print_values
mov dx, offset NewLine
mov ah, 9
int 21h
pop cx
LOOP O3_print_items
mov dx,offset new_chose_msg
mov ah,9
int 21h
jmp mainMenu
;////////////////////////////
no_entered_values:
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O3_msg_no_entered_values
mov ah, 9
int 21h
mov dx, offset invalid_chose_msg
mov ah,9
int 21h
jmp mainMenu
; --------------------------------------------- Option 4 ---------------------------------------------
option4:
cmp mixed_table[00],0
je no_entered_values
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O4_msg_showItems
mov ah, 9
int 21h
; print the items
mov di,0
mov cl,num_of_items
mov ch,0
O4_print_items: ; outerloop
push cx
mov cl,length_of_items
mov ch,0
O4_print_values:
mov dl,items_table[di]
Mov ah, 02h
int 21h
inc di
loop O4_print_values
pop cx
loop O4_print_items
mov dx,offset NewLine
mov ah,9
int 21h
; print the numbers
mov dx, offset O4_msg_showNums
mov ah, 9
int 21h
mov si,0
mov cl,num_of_items
mov ch,0
O4_print_numbers: ; outerloop
push cx
mov cl,length_of_items
mov ch,0
O4_print_items_numbers:
mov dl,numbers_table[si]
Mov ah, 02h
int 21h
inc si
loop O4_print_items_numbers
pop cx
loop O4_print_numbers
mov dx,offset NewLine
mov ah,9
int 21h
mov dx,offset new_chose_msg
mov ah,9
int 21h
jmp mainMenu
; --------------------------------------------- Option 5 ---------------------------------------------
option5:
cmp mixed_table[00],0
je no_entered_values
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O5_msg_showNames
mov ah, 9
int 21h
; print the items
mov di,0
mov cl,num_of_items
mov ch,0
O5_print_items:
push cx
mov cl,length_of_items
mov ch,0
O5_print_values:
mov dl,items_table[di]
Mov ah, 02h
int 21h
inc di
loop O5_print_values
pop cx
loop O5_print_items
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx,offset new_chose_msg
mov ah,9
int 21h
jmp mainMenu
; --------------------------------------------- Option 6 ---------------------------------------------
option6:
cmp mixed_table[00],0
je no_entered_values
; print the numbers
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx, offset O6_msg_showNums
mov ah, 9
int 21h
mov si,0
mov cl,num_of_items
mov ch,0
O6_print_numbers:
push cx
mov cl,length_of_items
mov ch,0
O6_print_items_numbers:
mov dl,numbers_table[si]
Mov ah, 02h
int 21h
inc si
loop O6_print_items_numbers
pop cx
loop O6_print_numbers
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx,offset new_chose_msg
mov ah,9
int 21h
jmp mainMenu
; --------------------------------------------- Option 7 ---------------------------------------------
Close:
mov dx, offset NewLine
mov ah, 9
int 21h
mov dx,offset new_chose_msg
mov ah,9
int 21h
mov dx,offset o7_msg_closing
mov ah,9
int 21h
mov ax, 4ch ; return control to DOS (exit program)
int 21h
Main endp
Code ends
end Main