.model small .stack 64 .data op1 db 11,?,11 dup(0) op2 db 11,?,11 dup(0) pro1 db 12 dup(0),'$' pro2 db 11 dup(0),'$' pro3 db 22 dup(0),'$' pro4 db 11 dup(0),'$' pro5 db 11 dup(0),'$' msg1 db 0dh,0ah,'**************************************************************' db 0dh,0ah,' This calculator only can bear 10 digits of operand!' db 0dh,0ah,' And the oprand shuld be no sign!' db 0dh,0ah,'**************************************************************',0dh,0ah,'$' msg2 db 0dh,0ah,'Please input the FIRST operand(Press ENTER to finish):','$' msg3 db 0dh,0ah,'Please input the SECOND operand(Press ENTER to finish):','$' msg4 db 0dh,0ah,'The summation is: ','$' msg5 db 0dh,0ah,'The margin is: ','$' msg6 db 0dh,0ah,'The product is: ','$' msg7 db 0dh,0ah,'The quotient is: ','$' msg8 db 0dh,0ah,'Sorry!The operand is error!',0dh,0ah,'$' .code main proc far start1:mov ax,seg op1 mov ds,ax mov ax,0900h mov dx,offset msg1 int 21h iop1: mov ax,0900h mov dx,offset msg2 int 21h mov ax,0a00h mov dx,offset op1 int 21h mov bx,offset op1 cmp byte ptr[bx+2],0dh jz exit call check cmp di,1 jz iop1 iop2: mov dx,offset msg3 mov ax,0900h int 21h mov ax,0a00h mov dx,offset op2 int 21h lea bx,op2 call check cmp di,1 jz iop2 mov ax,0900h mov dx,offset msg4 int 21h ;call addition mov ax,0900h mov dx,offset msg5 int 21h ;call subtract mov ax,0900h mov dx,offset msg6 int 21h ;call multiplay mov ax,0900h mov dx,offset msg7 int 21h ;call divide exit: mov ah,4ch int 21h main endp check proc near push bx inc bx inc bx start2:cmp byte ptr[bx],30h jb error cmp byte ptr[bx],39h ja error mov al,[bx] and al,0fh mov [bx],al inc bx cmp byte ptr[bx],0dh jnz start2 mov di,0 jmp exit2 error:mov dx,offset msg8 mov ax,0900h int 21h pop bx push bx inc bx con: mov byte ptr[bx],0 inc bx cmp byte ptr[bx],0dh jnz con mov byte ptr[bx],0 mov di,1 exit2:pop bx ret check endp

评论