www.pudn.com > 055Calculator.rar > Calculator.asm, change:2007-06-12,size:8841b


PUSHR MACRO  
	PUSH AX 
	PUSH BX 
	PUSH CX 
	PUSH DX 
	PUSH SI 
	PUSH DI 
ENDM 
; 
POPR MACRO 
	POP DI 
	POP SI 
	POP DX 
	POP CX 
	POP BX 
	POP AX 
ENDM 
; 
CLEAR MACRO X1,Y1,X2,Y2,COLOR; 清屏 
	PUSHR 
	; 
	MOV AH,6 
	MOV AL,0 
	MOV BH,COLOR 
	MOV CH,X1 
	MOV CL,Y1 
	MOV DH,X2 
	MOV DL,Y2 
	INT 10H 
	; 
	POPR 
ENDM 
; 
SET MACRO X,Y  ;设置光标位置 
    PUSHR 
	MOV AH,2 
	MOV DH,X 
	MOV DL,Y 
	MOV BH,0 
	INT 10H 
	POPR 
ENDM 
; 
DRAW MACRO X1,Y1,X2,Y2,COLOR,SIGN  ;画小方框 
	PUSHR 
	MOV AH,6 
	MOV AL,0 
	MOV BH,COLOR 
	MOV CH,X1 
	MOV CL,Y1 
	MOV DH,X2 
	MOV DL,Y2 
	INT 10H 
	MOV BL,Y1 
	INC BL 
	SET X2,BL 
	MOV DL,SIGN 
	MOV AH,2 
	INT 21H 
	POPR 
ENDM 
; 
SHOW MACRO ADDRES;显示字符串 
	PUSHR 
	LEA DX,ADDRES 
	MOV AH,9 
	INT 21H 
	POPR 
ENDM	 
; 
REVERSE MACRO ADDR,COUNT;字符串变返 
	LOCAL LL 
	PUSHR 
	; 
	MOV BX,2 
	MOV DX,0 
	MOV AX,COUNT 
	DIV BX 
	MOV CX,AX 
	LEA SI,ADDR  
	MOV DI,SI 
	ADD DI,COUNT 
	MOV AL,[DI] 
	CMP AL,'1' 
	JZ LL 
	MOV AL,'$' 
	MOV [DI],AL 
	DEC DI 
	JMP LL 
 
LL: 
	MOV AL,[SI] 
	XCHG AL,[DI] 
	MOV [SI],AL 
	INC SI 
	DEC DI 
	LOOP LL 
	POPR 
ENDM 
; 
JIAFA MACRO STRING1,STRING2,RESULT,COUNT;加法运算 
	LOCAL NEXT,LOOP1 
	PUSHR 
	 
	 
	MOV BX,LEN1 
    CMP BX,LEN2 
    JG NEXT 
    MOV BX,LEN2 
NEXT: 
	MOV COUNT,BX 
	MOV CX,BX 
	LEA SI,STRING1 
	LEA BX,STRING2 
	LEA DI,RESULT 
	; 
	CMP CX,1 
	JZ ONEBITE 
	; 
	CLC 
LOOP1: 
	MOV AH,0 
	MOV AL,[SI] 
	ADC AL,[BX] 
	AAA 
	PUSHF 
	OR AL,30H 
	POPF 
	MOV [DI],AL 
	INC SI 
	INC DI 
	INC BX 
	LOOP LOOP1 
	; 
	OR AH,30H 
	MOV [DI],AH 
	INC DI 
	MOV BYTE PTR [DI],' ' 
	INC DI 
	MOV BYTE PTR [DI],'$' 
	; 
    REVERSE RESULT,COUNT 
    ; 
    SET 7,32 
    SHOW RESULT 
	JMP EXIT 
ONEBITE: 
	MOV AL,[SI] 
	SUB AL,30H 
	MOV BL,[BX] 
	SUB BL,30H 
	ADD AL,BL 
	MOV AH,0 
	MOV BX,AX 
	SET 7,32 
	CALL DISPLAY 
EXIT: 
	POPR 
ENDM 
; 
JANFA MACRO STRING1,STRING2,RESULT,COUNT;减法运算 
	LOCAL LOOP4 
	PUSHR 
	PUSHF 
	; 
	MOV BX,LEN1 
    CMP BX,LEN2 
    JGE NEXT 
    MOV BX,LEN2 
    MOV SIGN,-1 
NEXT: 
	MOV COUNT,BX 
	MOV CX,BX 
	; 
	.IF SIGN==-1 
	LEA SI,STRING2 
	LEA BX,STRING1 
	.ELSE  
	LEA SI,STRING1 
	LEA BX,STRING2 
	.ENDIF 
	; 
	LEA DI,RESULT 
	CMP CX,1 
	JZ ONESUB 
	CLC 
LOOP4: 
	MOV AH,0 
	MOV AL,[SI] 
	SBB AL,[BX] 
	AAS 
	PUSHF 
	OR AL,30H 
	POPF 
	MOV [DI],AL 
	INC SI 
	INC DI 
	INC BX 
	LOOP LOOP4 
	MOV BYTE PTR [DI],' ' 
	INC DI 
	MOV BYTE PTR [DI],'$' 
	; 
	 REVERSE RESULT,COUNT 
    ; 
    SET 7,32 
    .IF SIGN==-1 
    MOV DL,'-' 
    MOV AH,2 
    INT 21H 
    SHOW RESULT 
    .ELSE 
    SHOW RESULT 
    .ENDIF 
    ; 
    JMP EXIT6 
ONESUB: 
    MOV AL,[SI] 
	MOV BL,[BX] 
	CMP AL,BL 
	JGE L8 
	MOV SIGN,-1 
	XCHG AL,BL 
L8: 
.IF SIGN==-1 
	SET 7,32 
	SUB AL,BL 
	PUSH AX 
	MOV DL,'-' 
	MOV AH,2 
	INT 21H 
	; 
	POP AX 
	MOV DL,AL 
	ADD DL,30H 
	MOV AH,2 
	INT 21H 
	;; 
	.ELSE 
	SET 7,32 
	SUB AL,BL 
	MOV DL,AL 
	ADD DL,30H 
	MOV AH,2 
	INT 21H 
	.ENDIF 
	; 
EXIT6: 
    POPF 
    POPR 
ENDM 
; 
CHANGE MACRO ADDRES,COUNT,DATA;乘法运算 
	LOCAL L16,QUITS 
	PUSHR 
	MOV CX,COUNT 
	; 
	LEA SI,ADDRES 
	DEC COUNT 
	ADD SI,COUNT 
L16: 
	MOV AL,[SI] 
	DEC SI 
	SUB AL,30H 
	JL QUITS 
	CMP AL,39H 
	JG QUITS 
	CBW 
	PUSH CX 
	XCHG AX,BX 
	MOV CX,10D 
	MUL CX 
	XCHG AX,BX 
	; 
	ADD BX,AX 
	POP CX 
	LOOP L16 
QUITS: 
	MOV DATA,BX 
	POPR 
ENDM 
; 
CHENGFA MACRO ADDRE1,LEN1,ADDRE2,LEN2,VALUE;字符串到十进制的转换 
	PUSHR 
	; 
	CHANGE ADDRE1,LEN1,DATA1 
	CHANGE ADDRE2,LEN2,DATA2 
	; 
	MOV AX,DATA1 
	MUL DATA2 
	; 
	LEA SI,VALUE 
	LEA SI,VALUE 
	MOV [SI],DX 
	ADD SI,2 
	MOV [SI],AX 
	; 
	SET 7,32 
	MOV BX,VALUE 
	.IF BX==0 
	JMP BELOW 
	.ELSEIF 
	CALL DISPLAY 
	.ENDIF 
BELOW: 
	MOV BX,VALUE[2] 
	CALL DISPLAY 
	POPR 
ENDM 
 
CHUFA MACRO ADDRE1,LEN1,ADDRE2,LEN2,DOT;除法运算 
	PUSHR 
	; 
	CHANGE ADDRE1,LEN1,DATA1 
	CHANGE ADDRE2,LEN2,DATA2 
	; 
	SET 7,32 
	MOV DX,0 
	MOV AX,DATA1 
	; 
	MOV BX,DATA2 
	DIV BX 
	; 
	MOV YUSHU,DX 
	MOV BX,AX 
    CALL DISPLAY 
    ; 
	.IF YUSHU==0 
	JZ QUIT4 
	; 
	.ELSE 
	MOV DL,'.' 
    MOV AH,2 
    INT 21H 
    ; 
    MOV CX,8 
 EE: 
 	MOV DX,0 
    MOV AX,YUSHU 
    MOV SI,10D 
    MUL SI 
    MOV BX,DATA2 
    DIV BX 
    PUSH DX 
    MOV BX,AX 
    CALL DISPLAY 
    POP DX 
    CMP DX,0 
    JZ QUIT4 
    MOV YUSHU,DX 
    LOOP EE 
    .ENDIF 
QUIT4: 
    POPR 
ENDM 
; 
DATAS SEGMENT 
    ;此处输入数据段代码   
    STRING  DB 50 DUP(?)  
    STRING1 DB 50 DUP('0') 
    STRING2 DB 50 DUP('0') 
    RESULT  DB 50 DUP('0')  
	MESS1   DB 'Calculator','$' 
	MESS2   DB 'THE INPUT EXCEDE THE BOUNT','$' 
    LEN     DW ? 
    LEN1    DW ? 
    LEN2    DW ? 
    COUNT   DW 0 
    ; 
    DATA1   DW 0 
    DATA2   DW 0 
    RESULT1 DW 0 
    ; 
    OVER    DW 0 
    YUSHU   DW 0 
    ; 
    FLAG  	DB 0 
    TABLE  	DW 10000,1000,100,10,1 
    FF     	DW 0 
    TAG     DB 'A' 
	GETRE   DB 'F' 
	SIGN    DB 0 
	DOTSIGN DB 0 
DATAS ENDS 
STACKS SEGMENT 
    ;此处输入堆栈段代码 
STACKS ENDS 
 
CODES SEGMENT 
MAIN PROC FAR 
    ASSUME CS:CODES,DS:DATAS,SS:STACKS 
START: 
	PUSH DS 
	XOR AX,AX 
	PUSH AX 
	; 
    MOV AX,DATAS 
    MOV DS,AX 
    ;此处输入代码据段代码 
     
    CALL DRAW1 
NEXTF:  
    CALL INPUT 
	; 
	.IF TAG=='q' 
	JMP QUIT 
	.ELSEIF TAG=='c' 
	CLEAR 6,32,7,48,83H 
	CALL CHONGZHI 
	.ELSE 
	; 
	CALL SEPRATE 
	; 
	CALL OPERATE 
    ; 
	CALL CHONGZHI 
	.ENDIF 
	JMP NEXTF 
QUIT: 
    RET 
MAIN ENDP 
 
 
;;;;;;;;; 
INPUT PROC 
 	PUSHR 
 	SET 6,32 
 	LEA SI,STRING 
NEXTFF: 
 	MOV AH,1 
 	INT 21H 
 	; 
 	MOV BL,GETRE 
 	CMP BL,'T' 
 	JZ  CHONG 
L4:  
	CMP AL,'q' 
	JZ EXIT24 
	; 
	CMP AL,'c' 
	JZ EXIT24 
	; 
	CMP AL,'C' 
	JZ EXIT24 
	CMP AL,0DH 
 	JZ EXIT1 
 	CMP AL,0AH 
 	JZ EXIT1 
 	MOV [SI],AL 
 	INC SI 
 	INC LEN 
 	 
 	JMP NEXTFF 
 	; 
	JMP EXIT1 
CHONG: 
	CALL DRAW1 
	MOV GETRE,'F' 
	SET 6,32 
	MOV DL,AL 
	MOV AH,2 
	INT 21H 
	JMP	L4  
	; 
EXIT24: 
	.IF AL=='q' 
	MOV TAG,'q' 
	.ELSE 
	MOV TAG,'c' 
	.ENDIF 
EXIT1: 
	POPR 
 	RET 
INPUT ENDP 
;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
SEPRATE PROC  
	PUSHR 
	PUSH BX 
	LEA BX,STRING 
	LEA SI,STRING1 
	LEA DI,STRING2 
	MOV CX,LEN 
	; 
	MOV AX,LEN 
	ADD BX,AX 
	DEC BX 
	; 
    MOV LEN1,0 
    MOV LEN2,0 
    ; 
L1: 
	MOV AL,DS:[BX] 
	DEC BX 
	CMP AL,'+' 
	JZ ADD1 
	CMP AL,'-' 
	JZ SUB1 
	CMP AL,'*' 
	JZ  MUL1 
	CMP AL,'/' 
	JZ  DIV1 
	; 
	MOV DS:[DI],AL 
	INC DI 
	INC LEN2 
	; 
	LOOP L1 
ADD1: 
	MOV FLAG,1 
	JMP DIVIDE 
SUB1: 
	MOV FLAG,2 
	JMP DIVIDE 
MUL1: 
	MOV FLAG,3 
	JMP DIVIDE 
DIV1: 
	MOV FLAG,4 
	JMP DIVIDE 
DIVIDE: 
	DEC CX 
LL1: 
	MOV AL,[BX] 
	DEC BX 
	MOV [SI],AL 
	INC SI 
	INC LEN1 
	LOOP LL1 
	; 
	POP BX 
	POPR 
	RET 
SEPRATE ENDP 
;;;;;;;;;;;;;;;;;; 
SEPRATE1 PROC 
	PUSHR 
	SET 12,1 
	LEA SI,STRING2 
	MOV DX,LEN2 
	DEC DX 
	ADD SI,DX 
	; 
	MOV CX,LEN2 
	; 
	MOV BX,CX 
	CALL DISPLAY 
LA: 
	MOV AL,[SI] 
	; 
	MOV DL,AL 
	MOV AH,2 
	INT 21H 
	; 
	DEC SI 
	SUB AL,30H 
	JL QUITS 
	CMP AL,39H 
	JG QUITS 
	CBW 
	PUSH CX 
	XCHG AX,BX 
	MOV CX,10D 
	MUL CX 
	XCHG AX,BX 
	ADD BX,AX 
	; 
	POP CX 
	LOOP LA 
QUITS: 
	MOV DATA2,BX 
	POPR 
	RET 
SEPRATE1 ENDP 
;;;;;;;;;;;;;;;; 
OPERATE PROC  
	PUSHR 
	MOV AL,FLAG 
	CMP AL,1 
	JZ  OADD 
	CMP AL,2 
	JZ  OSUB 
	CMP AL,3 
	JZ  OMUL 
	CMP AL,4 
	JZ  ODIV 
	JMP EXIT3 
OADD: 
	JIAFA STRING1,STRING2,RESULT,COUNT 
	JMP EXIT3 
OSUB: 
	JANFA STRING1,STRING2,RESULT,COUNT 
	JMP EXIT3 
OMUL: 
	CHENGFA STRING1,LEN1,STRING2,LEN2,RESULT1 
	JMP EXIT3 
ODIV:	 
	CHUFA STRING1,LEN1,STRING2,LEN2 
	JMP EXIT3 
EXIT3: 
	MOV GETRE,'T' 
	POPR 
	RET 
OPERATE ENDP 
; 
DISPLAY PROC 
	PUSHR 
	CMP BX,0 
	JZ ZERO 
	; 
	MOV FF,0 
	LEA SI,TABLE 
	MOV CX,5 
DIVE: 
	MOV AX,BX 
	MOV DX,0 
	DIV WORD PTR[SI] 
	MOV BX,DX 
	MOV DL,AL 
	; 
	CMP FF,0 
	JNZ PRINT 
	CMP DL,0 
	JE SKIP 
	MOV FF,1 
PRINT: 
	ADD DL,30H 
	MOV AH,2 
	INT 21H 
SKIP: 
	ADD SI,2 
	LOOP DIVE 
	; 
	JMP QUIT6 
ZERO: 
	MOV DL,30H 
	MOV AH,2 
	INT 21H 
	; 
QUIT6: 
	POPR 
	RET 
DISPLAY ENDP 
;; 
 
DRAW1 PROC 
	PUSHR 
	CLEAR 0,0,24,79,15H 
	CLEAR 5,30,20,50,0B4H 
	; 
	SET 5,30 
	SHOW MESS1 
	 
	CLEAR 6,32,7,48,73H 
	; 
	DRAW 9, 32,10,34,0E4H, '7' 
    DRAW 12,32,13,34,0E4H,'4' 
    DRAW 15,32,16,34,0E4H,'1' 
    DRAW 18,32,19,34,0E4H,'0' 
    ; 
    DRAW 9,37,10,39,0E4H,'8' 
    DRAW 12,37,13,39,0E4H,'5' 
    DRAW 15,37,16,39,0E4H,'2' 
    DRAW 18,37,19,39,0E4H,'.' 
    ; 
    DRAW 9,42,10,44,0E4H,'9' 
    DRAW 12,42,13,44,0E4H,'6' 
    DRAW 15,42,16,44,0E4H,'3' 
    DRAW 18,42,19,44,0E4H,'=' 
    ; 
    DRAW 9,47,10,49,0E4H,'/' 
    DRAW 12,47,13,49,0E4H,'*' 
    DRAW 15,47,16,49,0E4H,'+' 
    DRAW 18,47,19,49,0E4H,'-' 
    POPR 
    ; 
    RET 
DRAW1 ENDP 
;;;;;;;;;;;;;;;;;;;;;;; 
CHONGZHI PROC  
	PUSHR 
	LEA SI,RESULT 
	LEA DI,STRING1 
	LEA BX,STRING2 
	MOV CX,50 
	MOV AL,'0' 
HH: 
	MOV [SI],AL 
	MOV [DI],AL 
	MOV [BX],AL 
	INC SI 
	INC DI 
	INC BX 
	LOOP HH 
	 
	MOV LEN,0 
	MOV LEN1,0 
	MOV LEN2,0 
	MOV COUNT,0 
	MOV TAG ,'A' 
	MOV SIGN,0 
	MOV WORD PTR DATA1,0 
	MOV WORD PTR DATA2,0 
	MOV WORD PTR RESULT1,0 
	MOV WORD PTR YUSHU,0 
	POPR 
	RET 
CHONGZHI ENDP  
 
CODES ENDS 
 
    END START