; Find the phone number
Create a phone number table that can store 50 items, each of which includes two parts: the person's name (20 characters) and the phone number (8 characters)
The program can receive the input personal names and corresponding phone numbers and add them to the phone number table.
After new input, the program should re-sort the telephone number table by name
The program can receive the name of the person who needs to find the phone number, find its phone number from the phone number list, and then display it on the screen in the following format.
; Name Tel.
; XXXX XXXXX
Write the program as follows:
D_seg segment
Tel_tab dB 50 DUP (20 DUP (?), 8 DUP (?)) ; Phone number, Personal Name Record
Tel_tabtemp dB 50 DUP (20 DUP (?), 8 DUP (?)) Transfer to sort phone numbers and Personal Name Records
Strintru dB 'Welcome to use! '
DB 'you can continue to input your Tel. No. By input character I. ', 0dh, 0ah
DB 'if you want to find a no. You can input character y to do. ', 0dh, 0ah
DB 'if you want to exit, please input CHARACTER n. ',' $'
Strinput dB 0dh, 0ah, 'input name: ', 0dh, 0ah,' $'
Strinphone dB 'input a telephone number: ', 0dh, 0ah,' $'
Stryn dB 'Do you want a telephone number? (Y/n/I) ',' $'
Strname dB 0dh, 0ah, 'name? ', 0dh, 0ah,' $'
Strprint dB 'name Tel. ', 0dh, 0ah,' $'
Acpname dB 21 ,?, 21 DUP (?) ; Recipient's name
Nth1 DB 3 DUP (?)
Acptel dB 9 ,?, 9 DUP (?) ; Receiving phone number
N2db 3 DUP (?)
Temp_tel db 0; temporarily store the current offset address of tel_tab
Temp_teltemp db 0; temporary storage tel_tabtemp current offset address
Findname dB 20 DUP (?) ; Name of the person to be searched
Findtel dB 8 DUP (?) , 0dh, 0ah, '$'; phone number found
D_seg ends
;
Prog segment
Assume Cs: prog, DS: d_seg, ES: d_seg
Start:
Main proc far
;
PUSH DS
XOR ax, ax
PUSH AX
;
MoV ax, d_seg
MoV ds, ax
MoV es, ax
;
; Displays initial information
Lea dx, strintru
MoV ah, 09 h
Int 21 h
Call input_name; call the subprogram input_name to receive the person's name
RET
Main endp
;***********************************
Receiving name subprograms
Input_name proc near
Again:
; Displays prompt information for the input person name
Lea dx, strinput
MoV ah, 09 h
Int 21 h
;
; Recipient's name
Lea dx, acpname
MoV ah, 0ah
Int 21 h
;
Sub ch, ch; cleared
MoV Cl, acpname + 1; actual number of characters
Lea Si, acpname + 2; assigned to the first character address of a person's name
;
Sub BH, BH
MoV BX, offset tel_tab
Add Bx, word PTR temp_tel
;
MoV Di, BX; Name of the person in the current tel_tab
Rep movsb
For each input name, the offset address is moved 20
MoV ax, word PTR temp_tel
Add ax, 20
MoV word PTR temp_tel, ax
The prompt message for entering the phone number is displayed.
Lea dx, strinphone
MoV ah, 09 h
Int 21 h
; Receiving phone number
Lea dx, acptel
MoV ah, 0ah
Int 21 h
;
Sub ch, ch
MoV Cl, acptel + 1; actual number of characters
Lea Si, acptel + 2; first address of the received phone number
;
Sub BH, BH
MoV BX, offset tel_tab; first geological of tel_tab
Add Bx, word PTR temp_tel; current offset address
;
MoV Di, BX; first address of the target string
Rep movsb
Each time you enter a phone number, the offset is shifted back to 8
MoV ax, word PTR temp_tel
Add ax, 8
MoV word PTR temp_tel, ax
;
Call the name_sort subroutine to sort the telephone number table by name
; Call stor_name
Find_again:
; Displays the prompt whether to find the information
Lea dx, stryn
MoV ah, 09 h
Int 21 h
;
Get_key:
MoV ah, 01 H
Int 21 h
CMP Al, 'y'
Je yes; If 'y' is entered, it will jump to Yes
CMP Al, 'n'
Je no; If 'n' is entered, it will jump to no
CMP Al, 'I'; If 'I' is entered, enter the phone number again.
Je again
JNE get_key; if none of the input is, wait until y or N is input.
Yes:
; Call The lookup Program
Call name_search
JMP find_again; continue searching for the next number
; Output input name information
; Lea dx, strname
; MoV ah, 09 h
; Int 21 h
; Call the input_name subroutine to receive the person name
; JMP again; Continue
No:
RET
Input_name endp
;************************************
; Save the name subroutine
Stor_name proc near
Stor_name endp
;************************************
Receive the phone number and save the phone number subroutine
Inphone proc near
Inphone endp
;***********************************
; Telephone number table sort by person name subroutine
Name_sort proc near
Name_sort endp
;***********************************
Telephone number search subroutine
Name_search proc near
; Output input name information
MoV BX, 0
Lea dx, strname
MoV ah, 09 h
Int 21 h
; Recipient's name
Lea dx, acpname
MoV ah, 0ah
Int 21 h
;
Sub ch, ch; cleared
MoV Cl, acpname + 1; actual number of characters
Lea Si, acpname + 2; assigned to the first character address of a person's name
;
Lea Di, findname
Rep movsb
Next:
MoV CX, 19
;---------------------------------
Sub ah, ah
MoV ax, offset tel_tab
Add ax, BX
;---------------------------------
Lea Si, findname
MoV Di, ax
ClD
Repz cmpsb
Je A10
Add Bx, 28
Cmp bx, 1400
Jge exit
JMP next
A10:
MoV CX, 8
Add Bx, 20; the first address of the current phone number
;--------------------------------
Sub ah, ah
MoV ax, offset tel_tab
Add ax, BX
;--------------------------------
Lea Di, findtel
MoV Si, ax
Rep movsb
; Print the searched
Call printline
Exit:
RET
Name_search endp
;******************************
Show the person name and phone number subroutine
Printline proc near
; Display print format
Lea dx, strprint
MoV ah, 09 h
Int 21 h
; Name of the output person and phone number
Lea dx, findname
MoV ah, 09 h
Int 21 h
RET
Printline endp
;******************************
Prog ends
End start
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.