⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yeathy4.asm

📁 汇编语言的实验报告
💻 ASM
字号:
dataseg   segment

namepar   label    byte
maxnlen   db     21
actnlen   db     ?
_name    db     21 dup(?)  ;在MASM5.0下不能用name

phonepar  label    byte
maxplen   db     9
actplen   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     0
tel_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:dataseg
main    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     inputloop
a10:
      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     searchloop
showname:      
      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,bx
i20:
      mov     _name[bx],20h
      inc     bx
      loop    i20
      ret
input_name endp            
;*********************************************************
stor_name  proc    near
      inc     count
  cld     
      lea     si,_name
      mov     cx,10        ;把name中的前20个字符放入tel_tab中每一个人信息的前20个byte中
      rep     movsw
      ret
stor_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
      
      ret
input_stor_phone endp         
;*****************************************************************
name_sort  proc    near
      sub     di,56    
      mov     endaddr,di
ns10:
      mov     swapped,0
      lea     si,tel_tab
ns20:
      mov     cx,20
      mov     di,si
      add     di,28 ;下一个被比较的名字
      mov     ax,di
      mov     bx,si
      repe    cmpsb
      jbe     ns30 ;小于或等于不用交换
      call    npxchg
ns30:
      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_tab
da10:
      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,28
nase10:           
      lea     di,_name     ;存放待查找的人名地址
      mov     cx,10
      repe    cmpsw
      jcxz    nase_exit   ;相等
      
      add     bx,28       ;表中下一个比较的人名
      mov     si,bx
      cmp     si,endaddr
      jbe     nase10
notintab: 
      mov     cx,-1
      ret
nase_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
      ret
norecord:
      mov     ah,09h
      lea     dx,mess6
      int     21h           
      ret
printline  endp  
;************************************************************              
codeseg   ends
      end     main

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -