-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.asm
executable file
·167 lines (148 loc) · 2.53 KB
/
Calculator.asm
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
157
158
159
160
161
162
163
164
165
166
167
; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc\0_com_template.txt
org 100h
jmp main
num dd ?
count dd 1
num2 dd ?
signo db 0
signo2 db 0
main:
jmp loop_1
loop_1:
mov ah, 1
int 21h
mov cl,al
cmp al,'+' ;0Dh enter
je loop_2
cmp al,'-'
je negative
cmp al,'*'
je loop_2
cmp al,'/'
je loop_2
mov bl, al
sub bl, 30h ; queda en bx el numero actual
mov bh, 00h
mov ax, num
mov dx, 10
mul dx ; consigo el numero corrido
add bx, ax
mov num, bx
jmp loop_1
negative:
cmp num,0
jne loop_2
mov signo,1
jmp loop_1
negative2:
mov signo2,1
jmp loop_2
loop_2:
mov ah, 1
int 21h
cmp al, 3Dh
je operar
cmp al,'-'
je negative2
mov bl, al
sub bl, 30h ; queda en bx el numero actual
mov bh, 00h
mov ax, num2
mov dx, 10
mul dx ; consigo el numero corrido
add bx, ax
mov num2, bx
jmp loop_2
operar:
cmp signo,1
je niego
cmp signo2,1
je niego2
mov ax,num
mov bx, num2
cmp cl,'+' ;0Dh enter
je suma
cmp cl,'-'
je resta
cmp cl,'*'
je mult
cmp cl,'/'
je divi
niego:
mov ax, num
mov dx,0000h
mov bx, -1
mul bx
mov num, ax
mov signo,0
jmp operar
niego2:
mov ax, num2
mov dx,0000h
mov bx, -1
mul bx
mov num2, ax
mov signo2,0
jmp operar
suma:
add ax, bx
mov num,ax
jmp count_0
resta:
sub ax,bx
mov num,ax
jmp count_0
mult:
mul bx
mov num,ax
jmp count_0
divi:
div bx
mov num,ax
jmp count_0
count_0:
mov ax, count
mov dx,num
cmp num,0
jng negar
mov ax, count
cmp ax,num
jg count_dec
mov bx, 10
mul bx
mov count, ax
jmp count_0
negar:
mov ax, num
mov dx,0000h
mov bx, -1
mul bx
mov num, ax
mov dx, 0f0h
mov ah,2
int 21h
jmp count_0
count_dec:
mov dx, 0000h
mov ax, count
mov cx, 10
div cx
mov count, ax
loop_out:
mov dx, 0000h
mov ax, num
mov cx, count
div cx
mov num,dx
mov bx,ax
mostrar:
mov dx,bx
add dx,30h
mov ah, 2
int 21h
cmp count, 1
je fin
jmp count_dec
fin:
ret