编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来

 ;编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来
;author:野渡无人
;create date:2007-12-4
;***************************************************************
data segment
     No_of_name db 20
     No_of_phone db 8
     inbuf db 20 dup(?) 
     outname db 20 dup(?),'$'
     outphone db 8 dup(?),'$'
     message1 db 'please input name:','$'
     message2 db 'please input a telephone number:','$'
     message3 db 'NAME',16 dup(20h),'TEL.',13,10,'$'
     errormessage1 db 'you should input 8 numbers!',13,10,'$'
     errormessage2 db 'you input a wrong number!',13,10,'$'
     flag db ?
data ends
;**************************************************************
prog segment
;--------------------------------------------------------------
main proc far
      assume cs:prog,ds:data
start:
       push ds
       sub  ax,ax
       push ax
 
       mov  ax,data
       mov  ds,ax
       mov  flag,0

       lea  dx,message1
       mov  ah,09
       int  21h

       call input_name
       call crlf

       lea  dx,message2
       mov  ah,09
       int  21h

       call inphone
       call crlf

       cmp  flag,1
       je   exit

       call printline
exit:
       ret
main endp
;------------------------------------------------------------
input_name proc near
       push ax
       push dx
       push cx

       mov  cx,0
       mov  cl,No_of_name
       call getchar
      
       mov  ax,0
       mov  al,No_of_name
       sub  ax,cx

       mov  cx,ax
       mov  si,0
next1:      
       mov  al,inbuf[si]
       mov  outname[si],al
       inc  si
      
       loop next1

       pop  cx
       pop  dx
       pop  ax

       ret
input_name endp
;-------------------------------------------------------------
inphone proc near
       push ax
       push dx
      
       mov  cx,0
       mov  cl,No_of_phone
       call getchar

       cmp  cx,0
       jnz  error1

       mov  cl,No_of_phone  
       mov  si,0
      
next2:      
       mov  al,inbuf[si]
      
       cmp  al,30h
       jl   error2

       cmp  al,39h
       ja   error2

       mov  outphone[si],al
       inc  si
      
       loop next2
       jmp  exit2
error1:
       call crlf
       lea  dx,errormessage1
       mov  ah,09
       int  21h

       mov  flag,1
       jmp  exit2
error2:
       call crlf
       lea  dx,errormessage2
       mov  ah,09
       int  21h

       mov  flag,1
       jmp  exit2
exit2:
       pop  dx
       pop  ax

        ret
inphone endp
;---------------------------------------------------------
getchar proc near
        push ax
        push dx

        mov  di,0
rotate:
        mov  ah,01
        int  21h

        cmp  al,0dh
        je   exit1

        mov  inbuf[di],al
        inc  di

        loop rotate
exit1:
        pop  dx
        pop  ax
        ret
getchar endp
;----------------------------------------------------------
crlf  proc near
         push ax
         push dx

         mov  dl,0dh
         mov  ah,2

         int  21h
         mov  dl,0ah

         mov  ah,2
         int  21h
 
         pop  dx
         pop  ax

         ret

crlf endp
;---------------------------------------------------------
printline proc near
         push ax
         push dx

         lea  dx,message3
         mov  ah,09
         int  21h
        
  lea  dx,outname
  mov  ah,09
  int  21h

  lea  dx,outphone
  mov  ah,09
  int  21h

         pop  dx
         pop  ax

         ret
printline endp
;---------------------------------------------------------
prog ends
;*********************************************************
         end main

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值