正文

汇编实验4-查找电话号码2007-01-07 21:51:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/qiutao/22337.html

分享到:

IBM-PC汇编的一个实验: ;the fouthdataseg   segment namepar   label    bytemaxnlen   db     21actnlen   db     ?_name    db     21 dup(?)  ;在MASM5.0下不能用name哦 phonepar  label    bytemaxplen   db     9actplen   db     ?phone    db     9 dup(?) crlf    db     13,10,'$' endaddr   dw     ? mess1    db     'Input name:','$'mess2    db     'Input a telephone number:','$'mess3    db     'Do you want a telephone number?(Y/N)','$'mess4    db     'name?','$'mess5    db     'name',16 dup(' '),'tel',0dh,0ah,'$'mess6    db     'Not in the table.',0dh,0ah,'$'mess7    db     'Invalid input!',0dh,0ah,'$' count    db     0tel_tab   db     50 dup(20 dup(' '),8 dup(' '))temp    db     20 dup(' '),8 dup(' '),0dh,0ah,'$'swapped   db     0 dataseg   ends;**********************************************************************codeseg   segment   assume cs:codeseg,ds:dataseg,es:datasegmain    proc     far      push     ds      sub      ax,ax      push     ax            mov        ax,dataseg      mov         ds,ax      mov        es,ax;      cld      lea     di,tel_tab      ;di中存放表首地址inputloop:      ;提示'Input name'      mov     ah,09h      lea     dx,mess1      int     21h      ;      call    input_name      cmp     actnlen,0  ;没有输入人名时      jz     a10        ;直接跳到提示是否查找的地方      cmp     count,50   ;输入上限      je     a10      call    stor_name   ;保存人名到tel_tab                        ;提示'Input a telephone number'      mov     ah,09h      lea     dx,mess2      int     21h      ;      call    input_stor_phone ;输入并保存电话号码      jmp     inputloopa10:      cmp     count,1      jbe     searchloop ;如果没有输入或者输入一个       call    name_sort  ;排序      call    disp_all  ;显示所有searchloop:      lea     dx,mess3      mov     ah,09h      int     21h             mov     ah,01h      int     21h                  cmp     al,'N'      je     exit      cmp     al,'n'      je     exit      cmp     al,'Y'      je     showname      cmp     al,'y'      je     showname            mov     ah,09      lea     dx,crlf      int     21h       lea     dx,mess7 ;非法输入      mov     ah,09h      int     21h                  jmp     searchloopshowname:            mov     ah,09      lea     dx,crlf      int     21h                    lea     dx,mess4 ;当输入Y时,显示'name?'      mov     ah,09      int     21h             call    input_name ;输入要查找的人名      call    name_search ;查找      call    printline      jmp     searchloop     exit:      ret main    endp;******************************************************input_name proc    near            mov     ah,0ah      lea     dx,namepar      int     21h      mov     ah,02h      mov     dl,0ah ;换行      int     21h            mov     bh,0      mov     bl,actnlen      mov     cx,21      sub     cx,bxi20:      mov     _name[bx],20h      inc     bx      loop    i20      retinput_name endp            ;*********************************************************stor_name  proc    near      inc     count      cld           lea     si,_name      mov     cx,10        ;把name中的前20个字符放入tel_tab中每一个人信息的前20个byte中      rep     movsw      retstor_name  endp   ;*****************************************************                  input_stor_phone proc  near            mov     ah,0ah      lea     dx,phonepar      int     21h      mov     ah,02h      mov     dl,0ah ;换行      int     21h            mov     bh,0      mov     bl,actplen      mov     cx,9      sub     cx,bx ;计算剩下的长度is20:      mov     phone[bx],20h ;剩下的地方填充空格      inc     bx      loop    is20            cld           lea     si,phone      mov     cx,4      ;把phone中的前8个字符放入tel_tab中每一个人信息的后8个byte中      rep     movsw            retinput_stor_phone endp         ;*****************************************************************name_sort  proc    near      sub     di,56    ;仔细想想为什么是这样的      mov     endaddr,dins10:      mov     swapped,0      lea     si,tel_tabns20:      mov     cx,20      mov     di,si      add     di,28 ;下一个被比较的名字      mov     ax,di      mov     bx,si      repe    cmpsb      jbe     ns30 ;小于或等于不用交换      call    npxchgns30:      mov     si,ax      cmp     si,endaddr      jbe     ns20      cmp     swapped,0      jnz     ns10      ret                        name_sort  endp;*****************************************************npxchg   proc    near      mov     cx,14      lea     di,temp      mov     si,bx      rep     movsw             ;move lower item to save            mov     cx,14      mov     di,bx      rep     movsw            mov     cx,14       lea     si,temp       rep     movsw       mov     swapped,1       ret       npxchg   endp;************************************************************disp_all  proc    near      mov     ah,09h      lea     dx,mess5      int     21h      lea     si,tel_tabda10:      lea     di,temp      mov     cx,14      rep     movsw      mov     ah,09h      lea     dx,temp      int     21h      dec     count      jnz     da10      ret            disp_all  endp     ;*********************************************name_search proc    near                  lea     si,tel_tab      mov     bx,si      add     endaddr,28nase10:                 lea     di,_name     ;存放待查找的人名地址      mov     cx,10      repe    cmpsw      jcxz    nase_exit   ;相等            add     bx,28       ;表中下一个比较的人名      mov     si,bx      cmp     si,endaddr      jbe     nase10notintab:       mov     cx,-1      retnase_exit:       mov     si,bx      lea     di,temp      mov     cx,14      rep     movsw            ret                  name_search endp  ;*******************************************************printline  proc    near      cmp     cx,-1      je     norecord            mov     ah,09h      lea     dx,mess5      int     21h            mov     ah,09h      lea     dx,temp           int     21h      retnorecord:      mov     ah,09h      lea     dx,mess6      int     21h                 retprintline  endp  ;************************************************************              codeseg   ends      end     main 学校开课太变态了,汇编只上6个星期!

阅读(8148) | 评论(4)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册