Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » GeneralRSS Feeds

phonebook

Posted By: Jay Patel     Category: Assembly Language     Views: 18293

Project on phonebook

 
 .Model small
.Data
    msg1 db 10, 13, ' -----------------------------------------------------------', 10, 13
         db 10, 13, '                            PHONEBOOK' ,10,13   
         db 10, 13, ' -----------------------------------------------------------', 10, 13
         db ' $'
    msg2 db 10, 13, 10, 13, ' Enter Name: $'
    msg3 db 10, 13, 10, 13, ' Enter Contact Name : $'
    msg15 db 10, 13, 10, 13, ' Access denied!$'
    msg17 db 10, 13, 10, 13, ' Contact Deleted.$'
    msg24 db '*.', 0
    msg14 db 10, 13, 10, 13, 'No Contacts!$',10,13,10,13
    msg16 db 10, 13, 10, 13, 'Contact created.$'
    msg35 db 10, 13, 10, 13, ' Sorry Contact Not Match    !!$'
    msg36 db 10, 13, 10, 13, ' C.Call  E.Edit  D.Delete $'
    msg37 db 10, 13, 'Calling...'
          db 10, 13, 'Press any key to End Call$'
    msg26 db 10, 13, '$'
    msg27 db 10, 13, 'Press any key to continue$',10,13
    msg28 db 10, 13, 10, 13, ' Enter Number (Press Esc to stop):$' 
    msg31 db '$'
    msg6 db 10, 13, 10, 13, '  Number : $' 
    msg21 db 10, 13, 10, 13, ' Sorry Contact Not Match    !!$'
    msg30 db 10, 13, 10, 13, ' Search Name : $'

    buffer1 db 80, 0, 80 dup(0)
    buffer2 db 80, 0, 80 dup(0)
    msg32 db 10, 13, 'A.Add  S.Search $' ,10 , 13    
.Code
start :    
    mov ax, @Data
    mov ds, ax
begin :
    mov ax, 3h        ; clear screen by
    int 10h                   ; changing video mode
    call disp2
option:
    lea dx,msg32
    call disp1

    call readch               ; read choice
    and al, 0fh
    cmp al, 1                 ; branch to appropriate
    jnz a                     ; module depending on
    jmp cr_file               ; the choice
a :    cmp al, 3
    jz vw_file
    mov ax, 4c00h             ; exit program
    int 21h



cr_file:lea dx, msg2              ; module for creating a file
    call disp1
    call read1                ; read name of file to be
    lea dx, buffer1[2]        ; created
    mov cx, 0
    mov ah, 3ch               ; create the file
    int 21h
    push ax                   ; push file handle onto stack.
    lea dx, msg28             ; ask if data is to
    call disp1                ; be input
    call readch               ; read choice
    and al, 0fh
    cmp al, 9                 ; if choice = 'Y' or 'y'
    jnz no
    lea dx, msg29
    call disp1
    pop bx                    ; retrieve file handle from stack.
    mov buffer1[1], 0
write :    call readch               ; read data character by character.
    mov buffer1[0], al
    cmp buffer1[0], 27        ; check if character is 'Esc'(stop).
    jz no
    cmp buffer1[0], 0dh
    jne neol
    lea dx, msg26
    call disp1
    mov si, dx
    mov byte ptr ds:[si + 2], 0
    mov cx, 3
    jmp com
neol :    mov cx, 1
    lea dx, buffer1[0]
com :    mov ah, 40h               ; write to the file
    int 21h
    mov byte ptr ds:[si + 2], '$'
    jmp write
no :    lea dx, msg16             ; creation successful
    call disp1
    call readch
    jmp begin   



vw_file:lea dx, msg30             ; module to view the
    call disp1        ; contents of a file
    call read1                ; read name of file
    lea dx, msg6
    call disp1
    call disp1
    lea dx, buffer1[2]        ; open the file
    mov ax, 3d02h
    int 21h
    mov buffer2[0], 0
    cmp ax, 2                 ; error if file not found
    jnz v_err
    lea dx, msg14
    call disp1
    jmp endv
v_err : cmp ax, 3                 ; error if path not found
    jnz cont2
    ;jnz push
    lea dx, msg21
    call disp1
    jmp endv
cont2 :    mov bx, ax
    push ax
    mov cx, 1
    lea dx, buffer1
    mov ah, 3fh               ; read the file
    int 21h
    cmp ax, 0                 ; stop if end-of-file
        jz push
        jnz show2
show2 :     mov buffer1[1], '$'
    lea dx, buffer1
    call disp1
    pop ax
    jmp cont2
    cmp buffer1[0], 0dh
       ; jnz show
    inc buffer2[0]
    cmp buffer2[0], 23        ; check if end of page
    jnz show1
    ;jnz push
    lea dx, msg26
    call disp1
    call readch
    mov buffer2[0], 0
    lea dx, msg26
    call disp1
push:   mov ah,02
        mov al,0
    mov cx,0
    mov dx,10
    int 21
    ;int 21h
    ;push ax                   ; push file handle onto stack.
    lea dx, msg28             ; ask if data is to
    call disp1                ; be input
    call readch               ; read choice
    and al, 0fh
    cmp al, 9                 ; if choice = 'Y' or 'y'
    jnz no1
    lea dx, msg29
    call disp1
    pop bx                    ; retrieve file handle from stack.
    mov buffer1[1], 0
write1 :    call readch               ; read data character by character.
    mov buffer1[0], al
    cmp buffer1[0], 27        ; check if character is 'Esc'(stop).
    jz no1
    cmp buffer1[0], 0dh
    jne neol1
    lea dx, msg26
    call disp1
    mov si, dx
    mov byte ptr ds:[si + 2], 0
    mov cx, 3
    jmp com1
neol1 :    mov cx, 1
    lea dx, buffer1[0]
com1:    mov ah, 40h               ; write to the file
    int 21h
    mov byte ptr ds:[si + 2], '$'
    jmp write1
no1 :    lea dx, msg16             ; creation successful
    call disp1
    call readch
    jmp begin
    ;jmp cr_file
show1 :     mov buffer1[1], '$'
    lea dx, buffer1
    call disp1
    pop ax
    jmp cont2
endv :  call readch
    jmp begin
cm_dir :lea dx, msg9              ; module for removing directory
    call disp1
    call read1                ; read name of directory to
    lea dx, buffer1[2]        ; be removed
    mov ah, 3ah               ; remove directory
    int 21h
    cmp ax, 3                 ; error if path not found
    jnz err61
    lea dx, msg21
    call disp1
    jmp endg1
err61 :  cmp ax, 5                 ; error if access denied
    jnz dir1
    lea dx, msg15
    call disp1
    jmp endg
done20 : lea dx, msg20             ; deletion successful
    call disp1
endg1 :    call readch
        jmp begin


dir1:   mov ax, 3h                ; module for displaying
    int 10h                   ; contents of directory
    lea dx, msg24
    mov cx, 0
    mov ah, 4eh               ; Get first file
    int 21h                   ; in directory
    cmp ax, 18                ; Check if no files
    jnz list1                  ; in directory
    lea dx, msg14             ; Display message
    call disp1                ; 'File not found'
    call readch
    jmp begin
list1 :    mov ah, 2fh               ; Get dta address
    int 21h
    mov byte ptr es:[bx + 42], 0
    add bx, 1eh
    mov buffer1[0], 0
char1 :    mov dl, byte ptr es:[bx]  ; Get character of
    inc bx                    ; filename from DTA
    inc buffer1[0]
    cmp dl, '.'               ; Check if extension
    jnz cont30                 ; is starting
cont40 :    lea dx, msg31
    call disp1
    inc buffer1[0]
    cmp buffer1[0], 0bh       ; Check for end of filename
    jne cont40                 ; buffer - 13 characters
    jmp char1
cont30 :    mov ah, 02h               ; Display character
    int 21h                   ; of filename
    cmp dl, 0                 ; Check for end
    jne char1                  ; of file name
    lea dx, msg26
    call disp1
    inc cx
    cmp cx, 23                ; Check for end of page
    jne cont10
    lea dx, msg27
    call disp1
    call readch
    mov cx, 0
    lea dx, msg26
    call disp1
cont10 :    mov ah, 4fh               ; Get next file
    int 21h
        jnc list1
    lea dx, msg27
    call disp1
    call readch
    ;jmp begin
jmp dl_file1
cp_file:lea dx, msg6              ; module for copying a file
    call disp1                ; read name of file to
    call read1                ; to be copied
    mov cx, bx
    lea dx, msg7
    call disp1
    call read2                ; read path of destination
    mov buffer2[bx], '\'      ; directory
    inc bx
    mov ax, 2
cp :    mov si, ax                ; concatenating path and filename
    mov dl, buffer1[si]
    mov buffer2[bx], dl
    inc bx
    inc al
    cmp cx, ax
    jne cp
    mov cx, 0
    lea dx, buffer2[2]        ; create the file in
    mov ah, 3ch               ; destination directory
    int 21h
    cmp ax, 3                 ; Display error message
    jnz cont                  ; if path not found
    lea dx, msg21
    call disp1
    jmp cp_file               ; on error read data again
cont :    push ax
    lea dx, buffer1[2]        ; open source file
    mov ax, 3d00h
    int 21h
    push ax
rd :    pop bx
    lea dx, buffer1
    mov cx, 80h               ; read source file
    mov ah, 3fh
    int 21h
    cmp ax, 0                 ; check if entire file
    jz fin                    ; has been read
    mov cx, bx
    pop bx
    push bx
    push cx
    mov cx, ax
    lea dx, buffer1           ; write into new file to
    mov ah, 40h               ; complete copy task
    int 21h
    jmp rd                    ; read file further
fin :    lea dx, msg25             ; copy successful
    call disp1
    call readch
    jmp begin
        disp1 proc                ; module for display of
      mov ah, 09h             ; a string on screen
      int 21h
      ret
    disp1 endp

    readch proc               ; module for reading a
      mov ah, 01h             ; character from keyboard
      int 21h
      ret
    readch endp

    read1 proc                ; module for reading
      mov [buffer1], 80       ; first string
      lea dx, buffer1
      mov ah, 0ah             ; read string from keyboard
      int 21h
      mov bl, buffer1[1]
      mov bh, 0
      add bx, 2
      mov buffer1[bx], 0      ; ASCIIZ string, so
      ret                     ; terminate with 0
    read1 endp

    read2 proc                ; module for reading
      lea dx, buffer2         ; second string
      mov ah, 0ah
      int 21h
      mov bl, buffer2[1]
      mov bh, 0
      add bx, 2
      mov buffer2[bx], 0
      ret
    read2 endp
    end start
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on phonebook Or get search suggestion and latest updates.

Jay Patel
Jay Patel author of phonebook is from United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!