SIMPLE Calculator Program in EMU8086 8086 ASSEMBLY The chea
SIMPLE Calculator Program in EMU8086 - 8086 ASSEMBLY
The cheap calculator For this project, we will build a simple integer 4 function calculator. The functions will be addition, subtraction, multiplication and division. The project will be simplified by limiting the inputs to unsigned values less than or equal to 255. It will be possible to obtain sums greater than what fits into 8 bits, so that will have to be accounted for. Also, it will be possible to obtain differences that go negative. This will be accounted for. As for multiplication, we will see products that go into 16 bits. Division could yield a quotient with remainder in the 8 bit range In order to keep this project as simple as possible, we will make the following conditions: 1. Division will be limited to word divided by word operands. 2. Division will yield a quotient and remainder. Both must be displayed. No floating numbers 3. Multiplication will display up to 16 bit results, so you will need a 16 bit binary to ASCII conversion subroutine (Sound familiar?) 4. For negative values from subtraction, we will two\'s complement the result and print it with a minus sign in front of it. This will avoid the need for a special negative number conversion subroutine 5. For 9 bit sums, the low order 8 bits will go into AL, and the carry will be added into AH The standard 16 bit binary to ASCII conversion subroutine may be used on AX How to do this: Start with the dreaded flow chart. Write the program to read in values and then parse them Parse means to break something complex into simpler pieces. For example 147 202 There are 4 elements in this input, the first value, 147, the augend; an operation, plus; the second number, 202, the addend; and the final control character that will start the computation, the equal sign. We can use the spaces in the input as separators to help us break the input apart 1.You can use INT 21H, function 0AH to read in a string from the console. Point an index register, Sl or DI, to the start of the data. Remember, that start of data will be located at input + 2 2. Start reading bytes, one at a time from the input, transferring the bytes into a temporary memory buffer. When you hit the space, the first number has been read in. You may wantSolution
/ DATASG SEGMENT PARA \'Data\' 002 003 ques1 DB \"Enter the first number: $\" 004 ques2 DB \"Enter the second number: $\" 005 ques3 DB \"Enter the operation: $\" 006 num DW ? 007 num1 DW ? 008 ans DW ? 009 010 paralt label Byte 011 maxlen DB 4 012 actlen DB ? 013 dbdata DB 5 dup(\'$\') 014 015 016 DATASG ENDS 017 ;.............................................. 018 CODESG SEGMENT PARA \'Code\' 019 MAIN PROC FAR 020 ASSUME SS:STACKSG, DS:DATASG, CS:CODESG 021 MOV AX,DATASG ;Set address of data 022 MOV DS,AX ;Segment in DS 023 024 mov ah, 02H ;move cursor 025 mov bh, 0 026 mov dh, 9 027 mov dl, 20 028 Int 10H 029 030 mov ah, 09H 031 Lea DX, ques1 032 Int 21H 033 034 mov ah, 0AH ;for op1 035 Lea Dx, paralt 036 Int 21H 037 038 call con_num 039 Jmp Next 040 041 Next: mov num, ax 042 043 044 mov ah, 02H ;move cursor 045 mov bh, 0 046 mov dh, 11 047 mov dl, 20 048 Int 10H 049 050 mov ah, 09H 051 Lea DX, ques2 052 Int 21H 053 054 mov ah, 0AH ;op2 055 Lea Dx, paralt 056 Int 21H 057 058 call con_num 059 Jmp Next2 060 061 Next2: mov num1, ax 062 063 064 mov ah, 02H ;move cursor 065 mov bh, 0 066 mov dh, 13 067 mov dl, 20 068 Int 10H 069 070 mov ah, 09H 071 Lea DX, ques3 072 Int 21H 073 074 mov ah, 0AH ;op3 075 Lea Dx, paralt 076 Int 21H 077 078 Lea Bx, dbdata 079 mov cl, [bx] 080 cmp cl, 2AH 081 JE Time 082 cmp cl, 2BH 083 JE Plus 084 cmp cl, 2DH 085 JE Min 086 cmp cl, 2FH 087 JE Divi 088 089 Time: cmp num, 0 090 JL Inv 091 cmp num1, 0 092 JL Inv 093 mov ax, num 094 mul num1 095 mov ans, ax 096 Jmp Fin 097 098 Inv: mov ax, num 099 imul num1 100 mov ans, ax 101 Jmp Fin 102 103 Plus: mov ax, num 104 add ax, num1 105 mov ans, ax 106 Jmp Fin 107 108 Divi: cmp num, 0 109 JL IDivi 110 cmp num1, 0 111 JL IDivi 112 mov ax, num 113 div num1 114 mov ans, ax 115 Jmp Fin 116 117 IDivi: mov ax, num 118 idiv num1 119 mov ans, ax 120 Jmp Fin 121 122 Min: mov ax, num 123 sub ax, num1 124 mov ans, ax 125 Jmp Fin 126 127 Fin: mov ah, 02H ;move cursor 128 mov bh, 0 129 mov dh, 15 130 mov dl, 20 131 Int 10H 132 133 mov ah, 09H ;outputs user input 134 Lea Dx, dbdata 135 Int 21H 136 137 138 139 140 141 con_num Proc NEAR 142 143 push bx 144 push cx 145 push dx 146 147 Lea BX, dbdata 148 mov ax, 0 ;num 149 mov cx, 0 150 mov dl, 10 151 152 Keep: mov cl, [bx] 153 cmp cl, 0DH 154 JE Done 155 sub cx, 30H 156 mul DL 157 add ax, cx 158 Jmp Keep 159 160 Done: pop dx 161 pop cx 162 pop bx 163 164 ret 165 con_num Endp