-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProject_M_library.asm
More file actions
797 lines (698 loc) · 18.2 KB
/
Project_M_library.asm
File metadata and controls
797 lines (698 loc) · 18.2 KB
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
org 100h
.model small
.stack 100h
.data
header DB "- Library Application -",0Dh,0Ah
DB "*************************",'$'
NEWLINE DB 10,13,"$"
menu DB 0Dh,0Ah,0Dh,0Ah,"1- Display Books in library.",0Dh,0Ah
DB "2- Add book.",0Dh,0Ah
DB "3- Remove book.",0Dh,0Ah
DB "4- Exit.",0Dh,0Ah,
DB "Please enter your choice: ",'$'
book_name DB 0Dh,0Ah,0Dh,0Ah,"Please write the book name (max 17 character) and press Enter: ",'$'
book_type DB 0Dh,0Ah,"Please write the book type (max 10 character) and press Enter: ",'$'
book_num DB 0Dh,0Ah,0Dh,0Ah,"Please write the book number you want to remove and press Enter: ",'$'
book_list DB 0Dh,0Ah,0Dh,0Ah,"The Book List (Max 9 books)",0Dh,0Ah
DB 0Dh,0Ah,"No. Book Name Book Type",'$'
space DB " ",'$'
error_msg DB 0Dh,0Ah,"The book number does not exist",0Dh,0Ah,'$'
full_msg DB 0Dh,0Ah,"There is no place to add a new book, delete book first",0Dh,0Ah,'$'
book1_name DB " The lost boy ",'$'
book2_name DB " Night ",'$'
book3_name DB " Shape of light ",'$'
book4_name DB " Rebecca ",'$'
book5_name DB " The Brain ",'$'
book6_name DB " The lost boy ",'$'
book7_name DB 17 dup('$')
book8_name DB 17 dup('$')
book9_name DB 17 dup('$')
book1_type DB " Story",'$'
book2_type DB " Story",'$'
book3_type DB " Art",'$'
book4_type DB " Art",'$'
book5_type DB " Science",'$'
book6_type DB " Science",'$'
book7_type DB 12 dup('$')
book8_type DB 12 dup('$')
book9_type DB 12 dup('$')
available_book DB 1, 2, 3, 4, 5 ,6, 0, 0, 0
area DD 0
operation DB 0
.code
begin:
mov ax,@data
mov ds,ax
; print message for the header
MOV AH,09H
LEA DX,header
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
;================================================
start:
;code to choose one choice from the menu
MOV AH,09H
LEA DX, menu
INT 21H
get_choice:
; read the user choice
mov ah, 1
int 21h
; first choice
cmp al, '1'
je FIRST_CHOICE
; second choice
cmp al, '2'
je SECOND_CHOICE
; third choice
cmp al, '3'
je THIRD_CHOICE
; forth choice
cmp al, '4'
je FORTH_CHOICE
; loop back to get_choice until the user choose
jmp get_choice
;================================================
FIRST_CHOICE:
; print raduis msg
MOV AH,09H
LEA DX, book_list
INT 21H
lea si, available_book
mov bl, 0
print_book:
inc bl ; book counter
mov al, [si]
inc si
cmp al, 0 ; go to next book
je next_book
cmp al, 1 ; go to book 1
je book1
cmp al, 2 ; go to book 2
je book2
cmp al, 3 ; go to book 3
je book3
cmp al, 4 ; go to book 4
je book4
cmp al, 5 ; go to book 5
je book5
cmp al, 6 ; go to book 6
je book6
cmp al, 7 ; go to book 7
je book7
cmp al, 8 ; go to book 8
je book8
cmp al, 9 ; go to book 9
je book9
book1:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book1_name
MOV AH,09H
LEA DX, book1_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book1_type
MOV AH,09H
LEA DX, book1_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book2:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book2_name
MOV AH,09H
LEA DX, book2_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book2_type
MOV AH,09H
LEA DX, book2_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book3:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book3_name
MOV AH,09H
LEA DX, book3_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book3_type
MOV AH,09H
LEA DX, book3_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book4:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book4_name
MOV AH,09H
LEA DX, book4_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book4_type
MOV AH,09H
LEA DX, book4_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book5:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book5_name
MOV AH,09H
LEA DX, book5_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book5_type
MOV AH,09H
LEA DX, book5_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book6:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book6_name
MOV AH,09H
LEA DX, book6_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book6_type
MOV AH,09H
LEA DX, book6_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book7:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book7_name
MOV AH,09H
LEA DX, book7_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book7_type
MOV AH,09H
LEA DX, book7_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book8:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book8_name
MOV AH,09H
LEA DX, book8_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book8_type
MOV AH,09H
LEA DX, book8_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
book9:
; print new line
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book number
MOV AH,02H
MOV Dl, bl
add Dl, 48
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book9_name
MOV AH,09H
LEA DX, book9_name
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
; print space
MOV AH,09H
LEA DX, space
INT 21H
; print book9_type
MOV AH,09H
LEA DX, book9_type
add dx,02h ; to get rid of the space on the beginning or the buffer size
INT 21H
jmp next_book
next_book:
cmp bl, 9
jg start
jmp print_book
;================================================
SECOND_CHOICE:
lea si, available_book
mov bl, 0
add_book:
; check for empty place
mov al, [si]
inc si
inc bl ; book counter
cmp bl, 9
jg full_place ; there is no place to add a new book
cmp al, 0 ; there is empty place
je found_place
jmp add_book
found_place:
dec si
mov [si], bl ; save the book num in the list
mov al, bl ; al now have the number of the empty place to add the book
cmp al, 1 ; add book at place 1
je add_book1
cmp al, 2 ; add book at place 2
je add_book2
cmp al, 3 ; add book at place 3
je add_book3
cmp al, 4 ; add book at place 4
je add_book4
cmp al, 5 ; add book at place 5
je add_book5
cmp al, 6 ; add book at place 6
je add_book6
cmp al, 7 ; add book at place 7
je add_book7
cmp al, 8 ; add book at place 8
je add_book8
cmp al, 9 ; add book at place 9
je add_book9
; add book in place 1
add_book1:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book1_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book1_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 2
add_book2:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book2_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book2_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 3
add_book3:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book3_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book3_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 4
add_book4:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book4_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book4_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 5
add_book5:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book5_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book5_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 6
add_book6:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book6_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book6_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 7
add_book7:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book7_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book7_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 8
add_book8:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book8_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book8_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; add book in place 9
add_book9:
; print book_name msg
MOV AH,09H
LEA DX, book_name
INT 21H
; Get the book name
mov ah,0ah
lea dx, book9_name
int 21h
mov si, dx ; save the address for space padding
; print NEWLINE
MOV AH,09H
LEA DX, NEWLINE
INT 21H
; print book_type msg
MOV AH,09H
LEA DX, book_type
INT 21H
; Get the book type
mov ah,0ah
lea dx, book9_type
int 21h
mov di, dx ; save the address for end string
jmp space_pad
; when there is no space for new book
full_place:
; print full_msg
mov ah,0ah
lea dx, full_msg
int 21h
jmp start
; fill the rest of the name with space for printing
space_pad:
mov ax, 0
mov cx, 0
mov al, [si+1] ; get the length of the string
add al, 2 ; for the buffer size
mov cl, 17
sub cl, al ; initilaize the counter
add ax, si
mov si, ax ; go to character after the last character
space_loop:
mov [si], 32 ; add space to the name
inc si
loop space_loop
; add $ to the end of the book type string
mov ax, 0
mov cx, 0
mov al, [di+1] ; get the length of the string
add al, 2 ; for the buffer size
add ax, di
mov di, ax ; go to character after the last character
mov [di], '$' ; add $ to the end
jmp start
;================================================
THIRD_CHOICE:
; print book_num msg
mov ah,09h
lea dx, book_num
int 21h
; read the user choice
mov ah, 1
int 21h
sub al, 48
lea si, available_book
mov bl, 0
; check for book
check_book:
cmp al, [si]
je found_book
inc si
inc bl ; book counter
cmp bl, 9
jg wrong ; there is no place to add a new book
jmp check_book
found_book:
mov [si], 0
jmp start
wrong:
; print error_msg
mov ah,0ah
lea dx, error_msg
int 21h
jmp start
;================================================
FORTH_CHOICE:
mov ah,4Ch
int 21h