-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_16.asm
executable file
·200 lines (180 loc) · 3.01 KB
/
calc_16.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
; 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
cmp al, 008H
je borrar
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
borrar:
mov ax, num
mov dx, 0000h
mov bx, 10
div bx
mov num,ax
jmp loop_1
borrar_2:
cmp num2,0
je loop_1
mov ax, num2
mov dx, 0000h
mov bx, 10
div bx
mov num2,ax
jmp loop_2
loop_2:
mov ah, 1
int 21h
cmp al, 3Dh
je operar
cmp al,'-'
je negative2
cmp al, 008H
je borrar_2
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
oper_1:
cmp signo2,1
je niego2
oper_2:
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:
neg num
jmp oper_1
niego2:
neg num2
jmp oper_2
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:
cmp signo, 1
je div_neg_1
divi_1:
cmp signo2, 1
je div_neg_1
divi_2:
mov dx, 0
div bx
mov dh, signo
cmp dh, signo2
jne div_neg_res
mov num,ax
jmp count_0
div_neg_1:
neg ax
jmp divi_1
div_neg_2:
neg bx
jmp divi_2
div_neg_res:
neg ax
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