汇编语言子程序设计 查找电话号码
生活随笔
收集整理的這篇文章主要介紹了
汇编语言子程序设计 查找电话号码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
匯編語言子程序設計
( 鑒于網友對本博文比較感興趣,2012年5月新增了實驗報告中相關內容。 )實驗2.4 ?查找電話號碼 1:題目:查找電話號碼phone
2.實驗要求
1)要求建立一個可以存入50項的電話號碼表,每項包括人名(20字符)和電話號碼(8字符)兩部分;
2)程序可以接受用戶輸入的人名及相應的電話號碼,并把它們加入到電話號碼表中;
3)凡有新的輸入后,程序可以按人名對電話號碼進行排序;
4)程序可接收需要查找的電話號碼的人名,并從電話號碼表中查出電話號碼,再在屏幕上以如下格式顯示
name ? ? ? ? tel
xxxxx ? ? ? ?xxxxxxxxxx
程序解決方案
一:總體設計與模塊說明
總體設計(2012年5月新增)如下圖所示:
模塊說明:
1.main:作為主程序調用其他模塊,完成程序功能。
2:menu :作為主菜單供用戶選擇操作所用。
3:input_name:作為輸入姓名子程序塊。
4: input_phone:作為輸入電話號碼子程序。
5: ifchar:作為判斷輸入姓名是否含非字母字符的子程序。
6:ifnum:作為判斷輸入電話號碼是否含非數字字符的子程序。
7:store:存儲輸入姓名或者電話號碼等內容的子程序。
8 name_sort:對已經輸入的電話記錄按姓名排序的子程序。
9:name_search:在已經輸入的電話記錄中查找所需號碼的子程序。
10:printline:輸出已經查找到的電話記錄。
11:clear_screen:在菜單選擇之間,適時清除屏幕冗余性息的子程序。
12:cursor :清屏后光標重定位的子程序。
13:crlf:回車換行的子程序。
程序代碼清單:
*************************************************************************************** msg macro message ;輸出提示符的宏 lea dx,message mov ah,09 int 21h endm datasg segment tel_tab db 2700 dup(?),' count dw 0 count1 dw 0 count2 dw 0 count3 dw 0 count4 dw 15 count5 dw 0 result db 0 num dw 0 ifnumy dw 0 ifchary dw 0 window db ' **************************************************************************' ,13,10db ' A Telphonenumber Store And Search System' ,13,10db ' ' ,13,10db ' Author:HNU Dingqiao Wang 2010-6 ' ,13,10db ' ' ,13,10db ' **************************************************************************',13,10,';程序相關的界面 mess1 db ' Input Name( max 14 char):','mess2 db ' Input A Number( max 11 num):','mess4 db ' Not In The Table ,Check Your Spelling Or Try Again! ','mess5 db ' Result As follow : ',13,10db 'Name***********TEL********',13,10 ,';程序相關的界面 mess6 db '-----------------------------------------------',13,10,'mess7 db ' * Additem [Enter/Space]',13,10db ' * Search [S]',13,10db ' * View [V]',13,10db ' * Exit [Esc]',13,10,13,10db ' Make a choice ',13,10,'mess8 db ' Check Your Inputting,It Contains None Char !',13,10,';程序相關的提示符 mess9 db ' Check Your Inputting,It Contains None Number!',13,10,'mess10 db ' No Record , Check Your Inputting And Try Again!',13,10,'mess11 db ' The Name You want search:','tip db ' System Tips: ',13,10db ' You can press A Key List In The Menu ',13,10db ' Then System Will Work For You ',13,10,13,10,'name1 label byte max1 db 15 act1 db ? str1 db 15 dup(?) tel label byte max2 db 12 act2 db ? str2 db 12 dup(?) datasg ends ;------------------------------------------------ codesg segment assume cs:codesg,ds:datasg,es:datasg main proc far start: push ds sub ax,ax push ax mov ax,datasg mov ds,ax mov es,ax ;--------- msg window;程序相關的界面 call menu quit: ;返回DOS系統 mov ah,4ch int 21h main endp ;------------------------------------------------ menu proc near ;顯示選擇菜單,包括輸入、查看、查詢、退出 msg mess7 call crlf mov ah,07 int 21h cmp al,0dh ;鍵入回車則查詢相應紀錄 je inputproc;輸入 cmp al,20h ;鍵入空格則查詢相應紀錄 je inputproc;輸入 cmp al,'s' ;鍵入s則查詢相應紀錄 je sear ;查詢 cmp al,'v' ;鍵入v則查看所有紀錄 je allrecord;查看 cmp al,1bh;Esc鍵退出 je quit ;退出 jmp help allrecord: call viewall;調用查看已有紀錄子程序 jmp exitmenu inputproc: call input ;調用輸入子程序 jmp exitmenu sear: cmp count,0 je promp call clear_screen call name_search;調用電話號碼查詢子程序 jmp exitmenu promp: msg mess10 call crlf call menu help: mov dl,07 mov ah,02 int 21h call clear_screen ;清除屏幕 msg tip call menu exitmenu: ret menu endp ;------------------------------------------------ input proc near ;輸入子程序,調用輸入姓名及輸入電話號碼子程序 mov bx,num call input_name;調用輸入姓名函數 call input_phone;調用輸入號碼函數 inc count add bx,12 mov byte ptr tel_tab[bx-1],'mov num,bx call name_sort call clear_screen call menu ret input endp ;------------------------------------------------- input_name proc near;存入姓名函數 push cx lea dx,mess1 mov ah,09 int 21h ;------- lea dx,name1 ;將輸入姓名存入到緩沖區name1 mov ah,0ah int 21h ;------- mov cl,act1;檢驗輸入的人名是否包含非字母的字符 mov si,0 test1: mov al, str1[si] call ifchar cmp ifchary,'y' jne error1 goon: inc si loop test1 ;------- move1: mov cl,act1 lea si ,str1 lea di,tel_tab[bx] call store;輸入的電話紀錄人名存入電話表 call crlf pop cx jmp exitname error1: msg mess8 call crlf call menu exitname: ret input_name endp ;------------------------------------------------ input_phone proc near;存入電話號碼函數 push cx lea dx,mess2 mov ah,09h int 21h ;--------- lea dx,tel;將輸入姓名存入到緩沖區tel mov ah,0ah int 21h ;------- mov cl,act2 ;檢驗輸入的人名是否包含非數字的字符 mov si,0 test2: mov al, str2[si] call ifnum cmp ifnumy,'y' jne error2 inc si loop test2 ;-------------- move2: add bx,15 mov cl,act2 lea si ,str2 lea di ,tel_tab[bx] call store;輸入的電話號碼存入電話表 call crlf pop cx jmp exitphone error2: msg mess9 call crlf call menu exitphone: ret input_phone endp ;------------------------------------------------- ifchar proc near ;判斷輸入是否為姓名字母子程序,結果存入ifchary中 cmp al,'.' je permit cmp al,20h je permit cmp al,41h jb error1 cmp al,5ah jbe permit cmp al,61 jb error3 cmp al,7ah jnbe error3 permit: mov ifchary,'y' jmp exitif1 error3: mov ifchary,'n' exitif1: ret ifchar endp ;------------------------------------------------- ifnum proc near;判斷輸入是否為電話號碼數字子程序,結果存入ifnumy中 sub al,30h cmp al,0h jb error4 cmp al,9h jnbe error4 mov ifnumy,'y' jmp exitif2 error4: mov ifnumy,'n' exitif2: ret ifnum endp ;------------------------------------------------- store proc near ;存儲輸入內容程序函數 cld rep movsb;串傳送指令,存入相應的內容到電話表 ret store endp ;------------------------------------------------- name_sort proc near;按名字冒泡法排序函數 mov cx,count cmp cx,1 je exits dec cx lop2: mov count1,cx mov bx,0 lop3: call compare cmp result,'>' jne continue change: mov count2,cx mov cl, 26 mov di,0 exchange: ;排序時移動紀錄的程序段,本來想用rep movsb,但一直應為名字長度不同而出現錯誤 mov al,tel_tab[bx][di] xchg al,tel_tab[bx+27][di] mov tel_tab[bx][di],al inc di loop exchange mov cx,count2 continue: add bx,27 loop lop3 mov cx,count1 loop lop2 exits: ret name_sort endp ;------------------------------------------------ compare proc near;按名字15為循環比較函數,結果存貯到result中,供name_sort函數判斷 mov si,bx comp: mov al,tel_tab[si] cmp al,'Z' jnb goon2 add al,20h ;比較時不區分大小寫,遇到大寫轉換為小寫 goon2: mov dl, tel_tab[si+27] cmp dl,'Z' jnb goon3 add dl,20h ;比較時不區分大小寫,遇到大寫轉換為小寫 goon3: cmp al,dl jl exit4;兩個名字中a[i]<a[i+1],結果保存到result位'<' jg exit5;兩個名字中a[i]>a[i+1],結果保存到result位'>' inc si dec count4 jnz comp exit4: mov result ,'<' ret exit5: mov result ,'>' ret compare endp ;------------------------------------------------ name_search proc near;按姓名查找電話號碼 mov count5,0 msg window call crlf msg mess11 lea dx,name1 mov ah,0ah int 21h lea si,str1 mov cl,act1 test3: ;檢驗輸入的姓名中是否包含非字母 mov al,[si] call ifchar cmp ifchary,'y' jne error5 ;若包含非字母則提示并轉到菜單重新選擇 inc si loop test3 mov bx,0 mov cx,count;根據輸入的姓名,在電話表中循環查詢是否有此紀錄 search: push cx call searchresult ;調用大小寫兼容查詢子程序 continue2: add bx,27 pop cx loop search cmp count5,0 jnz exitsear msg mess10 msg mess6 call crlf call menu jmp exitsear error5: msg mess8 exitsear: msg mess6 mov count5,0 call menu ret name_search endp ;------------------------------------------------ searchresult proc near ;搜索結果的判斷子程序 call crlf lea si,str1 mov cl,act1 mov di,0 check: ;check段的作用為大小寫兼容查詢狀態 mov al,[si] cmp al,tel_tab[bx][di] ;算法為假設輸入為小寫,先匹配,無結果則轉換為大寫查詢,若仍然無結果, jne onece1 ;則可以斷定為輸入為大寫或者確實無結果,當輸入為大寫是先前的操作引起al值改變 je again ;此時應該將al+40h,再次判斷,若在不成功,則應該為的確沒有記錄。 onece1: sub al,20h cmp al,tel_tab[bx][di] jne onece2 je again onece2: add al,40h cmp al,tel_tab[bx][di] jne exitresult again: inc si inc di loop check getit: inc count5 call printline exitresult: ret searchresult endp ;------------------------------------------------ viewall proc near;顯示當前已存入所有經過排序的紀錄 call clear_screen;清屏 cmp count ,0 je exit8 ;當前無記錄時提示符 call crlf msg mess5 call crlf mov cx ,count mov bx,0 view: lea dx,tel_tab[bx] mov ah,09 int 21h call crlf add bx,27 loop view exit7: msg mess6 call crlf call menu jmp exitprint exit8: msg mess10 call crlf exitprint: msg mess6 call menu ret viewall endp ;------------------------------------------------ printline proc near;輸出查詢結果 cmp count5,1 jnbe print msg mess5 print: lea dx,tel_tab[bx] mov ah,09 int 21h call crlf ret printline endp ;------------------------------------------------- clear_screen proc near ;清除屏幕子程序 push ax push bx push cx push dx mov ah,6 mov al,0 mov bh,7 mov ch,0 mov cl,0 mov dh,24 mov dl,79 int 10h mov dx,0 mov ah,2 int 10h mov dh,0 call cursor pop dx pop cx pop bx pop ax ret clear_screen endp ;------------------------------------------------- cursor proc near ;重置光標位置子程序,置光標為第零行和第零列 push ax push bx push cx push dx mov ah,02 mov bh,00 mov dl,00 mov dh,00 int 10h xor bh,bh mov dh,0 mov dl,0 mov ah,02 int 10h pop dx pop cx pop bx pop ax ret cursor endp ;------------------------------------------------- crlf proc near ;輸出回車換行 push ax push cx mov dl,0dh mov ah,02h int 21h ;---------- mov dl,0ah mov ah,02h int 21h pop cx pop ax ret crlf endp ;------------------------------------------------ codesg ends end start **************************************************************************************
運行結果:
總結
以上是生活随笔為你收集整理的汇编语言子程序设计 查找电话号码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【机器学习】opencv-视频中的人脸检
- 下一篇: 【Python】模拟面试技术面试题答