计算器实现简单的加减乘除运算(小于65536的正数)
①从键盘输入算数的等式
②不接受复合算数如3+5*7
③按‘=’号输出结果
④按‘C’号作为CLEAR清零
程序分为输入模块,判断模块,计算模块,输出模块。
其他:增加了一些特性
①能够得出两个正数相减得到的负数
②能够计算除法中的余数
③比较美观
代码过长由于增加了一些特性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
DATA SEGMENT divisors DW 10000, 1000, 100, 10, 1 results DB 0,0,0,0,0,"$" ;存放五位数ASCII码 data ends STACK SEGMENT STACK ENDS CODE SEGMENT ASSUME CS:CODE MAIN PROC FAR MOV AX,DATA MOV DS,AX NOW: MOV AX,0 CALL INPUT PUSH BX ;------------------------ CMP AL,'+' JZ PLUS CMP AL,'-' JZ MINUS CMP AL,'*' JZ BY CMP AL,'/' JZ DIVD PLUS: CALL INPUT POP AX ADD AX,BX JMP NEXT MINUS: CALL INPUT POP AX CMP AX,BX JL LESS SUB AX,BX JMP NEXT LESS: SUB AX,BX NEG AX PUSH AX MOV DL,'-' MOV AH,02H INT 21H POP AX JMP NEXT BY: CALL INPUT POP AX MUL BX JMP NEXT DIVD: CALL INPUT POP AX CMP AX,BX JL LESS2 DIV BX JMP NEXT LESS2: PUSH AX MOV DL,30H MOV AH,02H INT 21H MOV DL,'~' MOV AH,02H INT 21H POP AX JMP NEXT ;--------------------------- NEXT: CALL OUTPUT JMP NOW MOV AH,4CH INT 21H RET MAIN ENDP ;--------------------- INPUT PROC NEAR MOV BX,0 NUM: MOV AH,1 INT 21H CMP AL,'C' JZ CLEAR CMP AL,'+' JZ EXIT CMP AL,'-' JZ EXIT CMP AL,'*' JZ EXIT CMP AL,'/' JZ EXIT SUB AL,30H JL EXIT CMP AL,9 JG EXIT CBW XCHG AX,BX MOV CX,10 MUL CX XCHG AX,BX ADD BX,AX JMP NUM CLEAR: MOV DL,0DH MOV AH,2 INT 21H MOV DL,0AH MOV AH,2 INT 21H MOV AX,0 MOV BX,0 JMP NUM EXIT:RET INPUT ENDP ;---------------------- OUTPUT PROC NEAR mov si, offset divisors mov di, offset results mov cx,5 CAL: mov dx,0 div word ptr [si] add al,30H mov byte ptr [di],al inc di add si,2 mov ax,dx LOOP CAL mov cx,4 mov di, offset results NZ: cmp byte ptr [di],'0' jne print inc di loop NZ print: mov dx,di MOV AH,9 INT 21H RET OUTPUT ENDP ;--------------------- CODE ENDS END MAIN |