MyRecord struct
name db 16 dup ('$')
phone db 16 dup ('$')
MyRecord ends
;
data segment
TheRecord MyRecord <>
string db 16 dup('$')
TipMsg db 'Please input your name:$'
TipMsg2 db 'Please input your phone:$'
ErrMsg db 'The Number should not be char!Please input phone again.$'
data ends
;
MYCODE segment
assume cs:MYCODE, ds:data
START:
mov ax , data
mov ds , ax
mov dx, offset TipMsg
call SHOWMSG
call NEWLINE
lea dx , TheRecord ;获取字符串首地址
mov byte ptr [TheRecord+0], 0dh ;设置读取字符串大小
mov ah , 0ah
int 21h ;读取字符串
GETPHONE:
mov dx, offset TipMsg2
call SHOWMSG
call NEWLINE
lea dx, TheRecord +16
mov byte ptr [TheRecord+16], 0dh
mov ah, 0ah
int 21h
;类型检查
mov cx, 0ch
CHECK:
mov si, offset TheRecord
add si, 18
lodsb
cmp al, '0'
jb ERR
cmp al, '9'
ja ERR
loop CHECK
OVER: ;注意,不可使用关键字
mov ax, 4c00h
int 21h
;
ERR:
mov dx, offset ErrMsg
call SHOWMSG
call NEWLINE
jmp GETPHONE
SHOWMSG PROC
mov ah, 9h
int 21h
ret
SHOWMSG ENDP
NEWLINE PROC
mov dl,0dh
mov ah,2h
int 21h
mov dl,0ah
mov ah,2h
int 21h
ret
NEWLINE ENDP
MYCODE ends
end START