;编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及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