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

📄 phonecheck.asm

📁 该程序的基本功能如下 1.建立一个可存放50项的电话号码表
💻 ASM
字号:
五、源程序
data_seg segment
   namcount dw 0                 ;存入名字的个数
   tel_tab db 50 dup(28 dup(' '))       

   nameitem label byte
   nmax db 21
   ncurlen db ?
   namefld db 21 dup(?)         ;姓名缓冲区

   phoneitem label byte
   pmax db 9
   pcurlen db ?
   phonefld db 9 dup(?)         ;电话号码缓冲区

   addend dw ?                 
   namtemp db 28 dup(?),13,10,'$'         
   swap db 0                           

   msg_count db 'Please enter the count  ',13,10,'$'
   msg_illcount db 'Error:The number of your enter exceed the limit of 50! Plesae input the number again!',13,10,'$'
   msg_illch db 'Error:The number of your enter is illegal! Please intput  the number again!',13,10,'$'
   msg_inputnam db 'Input name:','$'
   msg_inputerr db 'Error:Input error!,please input a name!',13,10,'$'
   msg_inputnum db 'Input a telephone number:','$'
   msg_inquire db 'Do you want to check a telephone number?(Y/N)','$'
   msg_sname db 'name?',13,10,'$'
   msg_outtitle db 'name                tel.',13,10,'$'
   msg_nomatch db 'No such name!Do you want to insert this item(Y/N)?',13,10,'$'
   msg_result db 'The Phone  listed  as follows:',13,10,'$'
   list  db 'names               tel',13,10,'$' 
data_seg ends

stack_seg segment para stack 'stack'     
 dw 256 dup(0)
stack_seg ends

code_seg segment

assume cs:code_seg,ds:data_seg,es:data_seg,ss:stack_seg
main proc far
start:
    mov ax,data_seg
      mov ds,ax                  
      mov es,ax                   

      cld                        
      lea di,tel_tab             

      lea dx,msg_count
      mov ah,9
      int 21h                     '

again:call decibin                
      cmp dx,2                   
      call crlf                
      je exit1                  

      push bx
      cmp bx,50 ;
      ja  return                  
                                 

repeat:pop bx
       cmp namcount,bx        
       je  choice                
       push bx                

       lea dx,msg_inputnam
       mov ah,9
       int 21h               
       call input_name            
       cmp ncurlen,0               
       je  choice
       call stor_name
       call input_phone           
       jmp  repeat              

choice:
       cmp namcount,1
       jb  return1                
       call name_sort             
rotate:
       lea dx,msg_inquire 
       mov ah,9
       int 21h                    
       mov ah,1
       int 21h                   

       cmp al,'y'
       je loop0
       cmp al,'Y'
       jne exit                   
       jmp loop0                

loop0: 
       call crlf
       lea dx,msg_sname                   
       mov ah,9
       int 21h                    

       call input_name            
       call name_search           
       jmp rotate                 

insert: 
       call crlf
       call stor_name                            
       call input_phone             
                                   
       call name_sort            
       call printline
       jmp rotate

 exit1: 
       lea dx,msg_illch        
       mov ah,9                
       int 21h
       jmp again

return:                      
       lea dx,msg_illcount   ; 
       mov ah,9
       int 21h
       jmp again

return1:
       lea dx,msg_inputerr 
       mov ah,9
       int 21h               

       jmp repeat            

exit: 
       call printline      

                           
       mov ah,7
       int 21h
       
       mov ax,4c00h
       int 21h
 main endp                          


name_search proc near       
       
        lea di,tel_tab                 
        push di                         
        mov bx,namcount          
loop1: 
        lea si,namefld           
        mov cx,20
        repe cmpsb                  
        je  found                       
        pop di                           
        add di,28                      
        push di
        dec bx
        jnz loop1                       

        lea dx,msg_nomatch
        mov ah,9
        int 21h                         

        mov ah,1
        int 21h                           
        cmp al,  'y'

        je insert
                           

        jne loop0                       
                          

found:  pop di
        lea dx,msg_outtitle
        mov ah,9
        int 21h

        mov si,di                      
        lea di,namtemp
        mov cx,28
        rep movsb

        lea dx,namtemp
        mov ah,9
        int 21h                          
        ret
name_search endp

decibin proc near                
        mov bx,0                            
        mov dx,2                      

newchar:
        mov ah,1
        int 21h                          

        sub al,30h
        jb  exit2                         
        cmp al,9
        ja  exit2                          
        cbw                                
        xchg ax,bx                     
        mov cx,10
        push dx
        mul cx                           
        xchg ax,bx                     
        add  bx,ax
        pop  dx
        dec  dx
        jnz  newchar                 

exit2: ret
decibin endp                         

input_name proc near          
                                                
        lea dx,nameitem
        mov ah,0ah
        int 21h                             

        call crlf                            

        mov bh,0
        mov bl,ncurlen               
        mov cx,21                      
        sub cx,bx

repeat1:mov namefld[bx],20h
        inc bx
        loop repeat1                    
        ret
input_name endp

stor_name proc near              
                                                
  inc namcount
        cld                                       
        lea si,namefld
        mov cx,20
        rep movsb                      
        ret
stor_name endp

input_phone proc near             
                                                  
        lea dx,msg_inputnum
        mov ah,9
        int 21h                                
        lea dx,phoneitem
        mov ah,10
        int 21h                                      
        mov bh,0
        mov bl,pcurlen
        mov cx,9                         
        sub cx,bx

repeat2:mov phonefld[bx],20h
        inc bx
        loop repeat2                      
        call crlf
        cld                                     
        lea si,phonefld
        mov cx,8
        rep movsb                       
        ret
input_phone endp

name_sort proc near                    
        push di
        push ax
        push bx
        cmp namcount,1
        jz  exit4                       

s1:    
        mov swap,0
        sub di,56                        
        mov addend,di                      
        lea si,tel_tab

s2:    
        mov cx,20                          
mov di,si
        add di,28                      
        mov ax,di                            
 mov bx,si                      ;
        repe cmpsb                  ;
        jbe s3
        call exchange

s3:    
        mov si,ax
        cmp si,addend
        jbe s2                           
        cmp swap,0                 
        jnz s1

exit4: 
        pop bx
        pop ax
        pop di
        ret

name_sort endp

exchange proc near           
        mov cx,28
        lea di,namtemp
        mov si,bx
        rep movsb
        
        mov cx,28
        mov di,bx
        rep movsb
        
        mov cx,28
        lea si,namtemp
        rep movsb
        
        mov swap,1
        ret
exchange endp

printline proc near                    ;输出排序结果
        push di
        push namcount                  
  
        call crlf                       

        lea dx,msg_result          
        mov ah,9
        int 21h  
                                       ;显示升序输出姓名、电话
        lea dx,list
        mov ah,9
        int 21h                         
        
        call crlf
        call crlf
        
        lea si,tel_tab
loop2:  
        lea di,namtemp
        mov cx,28                       
        rep movsb                       
        lea dx,namtemp
        mov ah,9
        int 21h                             ;显示姓名、电话
        dec namcount                       
        jnz loop2                         

        pop namcount
        pop di
        ret
printline endp

deciasc proc near                          ;把10进制数转换成相应的ASCII码
        mov ch,10d
        mov cl,10d

    re:                                       ;判断退出条件
        cmp ch,0
        je quit

                                                
        mov al,bl;
        cbw
        div ch;
        mov bl,ah                            

 call printit

       mov al,ch
       cbw
       div cl
       mov ch,al

       jmp re

quit:
     ret
   deciasc endp

printit  proc near
                                              
      add al,30h
      mov dl,al
      mov ah,2
      int 21h
      ret      
printit  endp

crlf proc near 
                                            
        mov dl,0dh                           
        mov ah,2
        int 21h
        mov dl,0ah
        mov ah,2
        int 21h
        ret
crlf endp

code_seg ends
  end start

⌨️ 快捷键说明

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