-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneNumbersSystem.asm
More file actions
493 lines (480 loc) · 9.67 KB
/
PhoneNumbersSystem.asm
File metadata and controls
493 lines (480 loc) · 9.67 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
; multi-segment executable file template.
data segment
; add your data here!
pkey db "press any key...$"
count db 0
count2 dw 0
count3 dw 0
count4 dw 0
count5 db 0
count6 dw 0
count7 dw 0
counter dw -1
counter2 dw -1
contacts db 400 dup(0) ; Array for storing contacts
ordredContacts db 400 dup(0) ;array for ordered contacts
nameChoisi db 20 dup(0)
counter3 dw 0
length dw 1
lengthOrdredContacts dw 0
lengthname dw 0
endname db 0
endname2 dw 0
namemod db 20 dup(0)
namedel db 20 dup(0)
newline db 13,10,'$'
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
include emu8086.inc ;include emu8086.enc library to use the function printn
;-----------------------------------------------------
; menu
;-----------------------------------------------------
printn '********************************'
printn '*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*'
printn '*°°°°° °° °° S°°°°°°°°°*'
printn '*°°°°° °°°°°° °°°°°° Y°°°°°°°°°*'
printn '*°°°°° °°°°°° °°°°°° S°°°°°°°°°*'
printn '*°°°°° °° °° T°°°°°°°°°*'
printn '*°°°°° °°°°°°°°°° °° E°°°°°°°°°*'
printn '*°°°°° °°°°°°°°°° °° M°°°°°°°°°*'
printn '*°°°°° °° °° 2°°°°°°°°°*'
printn '*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*'
printn '*°°Benmabrouk°Mariya°Group°14°°*'
printn '*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*'
printn '********************************'
menu:
printn ' ' ; Print an empty line for spacing
printn ' ------------------------------ '
printn '| Choose an operation : |'
printn '| 1-> add a contact |'
printn '| 2-> view all contacts |'
printn '| 3-> search a contact |'
printn '| 4-> modify a contact |'
printn '| 5-> delete a contact |'
printn '| 6-> exit |'
printn ' ------------------------------ '
mov ax,0
mov [endname],0
mov [endname2],0
; Wait for user input
mov ah,01
int 21h
;----------------------------------------------
; add content
;----------------------------------------------
addContant:
cmp al,'1' ; Check if the user pressed '1' (Add Contact)
jne ViewAllContact ; If not jump to ViewAllContact
mov bl,[count]
cmp bl,16
je AddressBookFull
inc [count] ; Increment contact count
inc [count2]
printn 'enter the information of the contact'
printn ' enter the name'
mov [contacts],' ' ; Initialize by inserting a space at the beginning
LoopName:
mov ah,1
int 21h
cmp al,13 ; Initialize by inserting a space at the beginning
je enternumber
mov si,[length]
mov di,[lengthOrdredContacts]
inc [length]
inc [endname]
inc [endname2]
mov [contacts+si],al
cmp [endname],10
je enternumber
jmp LoopName
enternumber:
mov dx,10
sub dx,[endname2]
mov [contacts+si+1],' '
printn ' enter the number (contain 10 digits)'
mov cx,10
LoopNumber:
mov ah,1
int 21h
inc [length]
mov si,[length]
mov [contacts+si],al
loop LoopNumber
mov [contacts+si+1],' ' ; Initialize by inserting a space at the beginning
mov [contacts+si+2],'$' ; Add end marker ('$') to indicate end of contact
add [length],2
jmp menu
AddressBookFull:
printn 'the address book is full, you can not add a contact '
jmp menu
;--------------------------------------------
; view all contents
;--------------------------------------------
ViewAllContact:
cmp al,'2' ; Check if the user pressed '2' (view all Contact)
jne SearchContact ; If not jump to Search for a Contact
; Check if the address book is empty
mov bl,[count]
cmp bl,0
jne notEmpty ; If not empty, continue
printn 'the address book is empty'
jmp menu
notEmpty:
printn ' ' ; Print an empty line for spacing
mov bl,[count]
cmp bl,1
je exist1
mov si,1 ; Start from position
mov di,0
mov dx,0
etMov1:
mov al,[contacts+si]
cmp al,'$' ; Check if end of contacts
je etMov2 ; If '$' found, move to next step
etMov3:
mov al,[contacts+si]
cmp al,' '
je etMov4
mov [ordredContacts+di],al
inc dx
inc si
inc di
jmp etMov3
etMov4:
mov [count7],10
sub [count7],dx ; Calculate how many spaces are needed
mov dx,0
add di,[count7]
inc si
; Calculate how many spaces are needed
mov cx,10
etMov5:
mov al,[contacts+si]
mov [ordredContacts+di],al
inc si
inc di
loop etMov5
inc si
jmp etMov1
etMov2:
mov [ordredContacts+di],'$'
mov ax,[count2]
cmp ax,1
je et5
mov cx,[count2]
et1:
mov ax,0
mov [count6],1
et2:
mov bx,[count6]
cmp bx,[count2]
je et5
mov bl,20
mul bl
mov si,ax
div bl
add ax,1
mul bl
mov di,ax
div bl
mov [count3],si
mov [count4],di
mov [count5],0
inc [count6]
et3:
mov dl,0
inc [count5]
mov bl,[ordredContacts+si]
cmp bl,[ordredContacts+di]
jl et2
jg et4
inc si
inc di
mov bh,[count5]
cmp bh,20
je et2
jmp et3
et4:
mov si,[count3]
mov di,[count4]
et6:
mov bl,[ordredContacts+si]
mov bh,[ordredContacts+di]
mov [ordredContacts+si],bh
mov [ordredContacts+di],bl
inc si
inc di
inc dl
cmp dl,20
je et2
jmp et6
et5:
loop et1
lea dx,ordredContacts
mov ah,9
int 21h
jmp menu
exist1:
; If only one contact, directly print contacts
lea dx,contacts
mov ah,9
int 21h
jmp menu
;---------------------------------------------------------
; search a content
;---------------------------------------------------------
SearchContact:
cmp al,'3' ; Check if the user pressed '3' (Search a contact)
jne ModifyContact ; If not jump to ModifyContact
; Check if the address book has any contacts
cmp [length],1
je isempty ; If no contacts, display message
printn 'enter the name of the contact that you need to find it'
mov si,1
mov [nameChoisi],' '
; Read user input for the name
choicename:
mov ah,1
int 21h
cmp al,13
je compare
mov [nameChoisi+si],al
cmp si,10
je compare
inc si
loop choicename
compare:
mov [nameChoisi+si],' '
inc si
mov [nameChoisi+si],'.'
mov [lengthname],si
mov si,0
mov di,0
co:
cmp [contacts+si],'$'
je notexist
inc [counter]
first:
mov bl,[nameChoisi+di]
mov al,[contacts+si]
cmp al,bl
jne ne
eq:
inc di
inc si
mov dl,[nameChoisi+di]
cmp dl,'.'
jne first
je exist
ne:
inc si
sub si,di
mov di,0
jmp co
exist:
printn 'is exist'
printn 'the number of this name is :'
mov cx,10
mov si,0
add si,[counter]
add si,[lengthname]
readNumber:
mov dl,[contacts+si]
inc si
mov ah,2
int 21h
loop readNumber
jmp menu
notexist:
printn 'this name does not exist in the address book'
jmp menu
isempty:
printn 'the address book is empty'
jmp menu
;---------------------------------------------
; modify contact
;---------------------------------------------
ModifyContact:
cmp al,'4'
jne DeleteContact
mf:
printn '--------------------------'
printn ' 1-chooce a name'
printn ' 2-exit'
printn '--------------------------'
mov ah,1
int 21h
byname:
cmp al,'1'
jne ex
printn 'enter the name of the contact that you need to modify its number'
mov [counter2],-1
mov [counter3],0
mov si,1
mov [namemod],' '
namemodify:
mov ah,1
int 21h
cmp al,13
je fnm
mov [namemod+si],al
cmp si,10
je fnm
inc si
jmp namemodify
fnm:
mov [namemod+si],' '
inc si
mov [namemod+si],'.'
mov [counter3],si
mov si,0
mov di,0
repeat:
mov al,[contacts+si]
cmp al,'$'
je NameNotExist
inc [counter2]
booclecmp:
mov al,[contacts+si]
cmp al,[namemod+di]
jne notEqCmp
inc si
inc di
mov al,[namemod+di]
cmp al,'.'
jne booclecmp
je NameExist
notEqCmp:
sub si,di
xor di,di
inc si
jmp repeat
NameNotExist:
printn 'this name does not exist in the address book'
jmp mf
NameExist:
printn 'this name is exist in the address book'
printn 'enter the new number'
mov si,[counter2]
add si,[counter3]
mov cx,10
newNumber:
mov ah,1
int 21h
mov dl,al
mov [contacts+si],al
inc si
loop newNumber
jmp mf
ex:
cmp al,'2'
jne notex
printn 'exit'
jmp menu
notex:
printn 'this option does not exist'
jmp mf
;---------------------------------------------
; delete a contact
;---------------------------------------------
DeleteContact:
cmp al,'5'
jne Exit
printn 'enter the name of the contact that you need to delete it'
mov [counter3],0
mov [counter2],-1
mov si,1
mov [namedel],' '
namedelete:
mov ah,1
int 21h
cmp al,13
je fnmdel
mov [namedel+si],al
cmp si,10
je fnmdel
inc si
jmp namedelete
fnmdel:
mov [namedel+si],' '
inc si
mov [namedel+si],'.'
mov [counter3],si
mov si,0
mov di,0
CmpNameDel:
cmp [contacts+si],'$'
je NameDelNotExist
inc [counter2]
repeatCmp:
mov al,[contacts+si]
cmp al,[namedel+di]
jne ndel
inc si
inc di
mov al,[namedel+di]
cmp al,'.'
je NameDelExist
jmp repeatCmp
ndel:
sub si,di
xor di,di
inc si
jmp CmpNameDel
NameDelNotExist:
printn 'this name does not exist in the address book'
jmp menu
NameDelExist:
printn 'this name is exist in the address book'
dec [count]
mov si,[counter2]
mov di,[counter2]
add di,[counter3]
add di,10
mov cx,[length]
add cx,24
boocleDelete:
mov al,[contacts+di]
mov [contacts+si],al
inc si
inc di
loop boocleDelete
printn 'the contacts after deletion (not ordred)'
lea dx,contacts
mov ah,9
int 21h
jmp menu
;---------------------------------------------
; exit
;---------------------------------------------
Exit:
cmp al,'6'
jne OptionDoesNotExist
printn 'Exit'
jmp finally
;---------------------------------------------
;option does not exis
;---------------------------------------------
OptionDoesNotExist:
printn 'This option does not exist'
jmp menu
;_____________________________________________
finally:
lea dx, pkey
mov ah, 9
int 21h ; output string at ds:dx
; wait for any key....
mov ah, 1
int 21h
mov ax, 4c00h ; exit to operating system.
int 21h
ends
end start ; set entry point and stop the assembler.