-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.asm
259 lines (228 loc) · 2.77 KB
/
1.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
;<Program title>
jmp start
;data
;INPUT DATA 8 FROM BIT9291 AND 9292 LOCATION
READ8: NOP
LXI H, 9291h
MOV B, M
LXI H, 9292h
MOV C, M
MOV H, C
MVI C, 0
MVI L, 0
RET
;VARIANT READER
READDASH8: NOP
LXI H, 9292h
MOV B, M
LXI H, 9291h
MOV C, M
MOV L, C
MVI C, 0
MVI H, 0
RET
;INPUT DATA 16-BIT FROM 9293(9294) AND 9295(9296)LOCATION
READ16: NOP
CALL RESET
LXI H, 9293h
MOV B, M
LXI H, 9294h
MOV C, M
LXI H, 9295h
MOV D, M
LXI H, 9296h
MOV E, M
XCHG
LXI D, 0
MVI A, 0
RET
;ADD EIGHT TIMES FOR 8-BIT MULTIPLICATION
ADDEREIGHT: NOP
ADD B
DCR H
JNZ ADDEREIGHT
MOV H, A
RET
;ADD 16-BIT INTEGERS
ADDER16: NOP
CALL RESET
CALL READ16
DAD B
CALL RESETH
RET
;ADD EIGHT BIT INTEGERS
ADDER8: NOP
CALL RESET
CALL READ8
MOV A, H
ADD B
MOV H, A
CALL RESETH
Rst 5
;SUBTRACT EIGHT BIT INTEGERS
SUB8: NOP
CALL RESET
CALL READ8
MOV A, H
SUB B
MOV H, A
CALL RESETH
Rst 5
;COMPARE PART OF 16-BIT MULTIPLIER
COMPARE: NOP
CMP B
JNZ ADDERSIXTEEN
RET
;ADD 16 TIMES FOR 16-BIT MULTIPLICATION
ADDERSIXTEEN: NOP
DAD D
DCX B
CMP C
JNZ ADDERSIXTEEN
JZ COMPARE
RET
;RESET ALL REGISTERS
RESET: NOP
MVI A, 0
LXI H, 0
LXI B, 0
LXI D, 0
RET
;RESET ALL EXCEPT H & L
RESETH: NOP
MVI A, 0
LXI B, 0
LXI D, 0
RET
;MULTIPY 8 BIT INTEGERS
MULTIPLY8: NOP
CALL RESET
CALL READ8
CALL ADDEREIGHT
CALL RESETH
Rst 5
;MULTIPLY 16 BITS
MULTIPLY16: NOP
CALL RESET
CALL READ16
XCHG
CALL ADDERSIXTEEN
CALL RESETH
Rst 5
;SELECT OPERATION TO PERFORM
SELECTOPERATION: NOP
CPI 0
JZ MULTIPLY8
CPI 1
JZ MULTIPLY16
CPI 2
JZ ADDER8
CPI 3
JZ ADDER16
CPI 4
JZ SUB8
CPI 5
JZ subtract16
CPI 6
JZ divide
CPI 7
JZ divide16
CPI 8
JZ mod8
CPI 9
JZ mod16
RET
;MOD 8-BIT
mod8: nop
CALL RESET
CALL READDASH8
call shift
call shift
call shift
call shift
call shift
call shift
call shift
call shift
call RESETH
rst 5
;SUBTRACT-16
subtract16: nop
CALL RESET
CALL READ16
mov a,l
sub c
mov l,a
mov a,h
sbb b
mov h,a
CALL RESETH
Rst 5
;DIVIDE-16
subtractdash16: nop
mov a,l
sub c
mov l,a
mov a,h
sbb b
mov h,a
ret
divide16: nop
CALL RESET
CALL READ16
while: nop
inx d
call subtractdash16
jnc while
dcx d
XCHG
rst 5
;MOD 16-BIT
mod16: nop
CALL RESET
CALL READ16
while1: nop
call subtractdash16
jnc while1
dad b
call RESETH
rst 5
;DIVISION 8-BIT
inc_quo: nop
mov h,a
mov a,c
add a
adi 0001h
mov c,a
ret
shift: nop
dad h
mov a,h
sub b
jnc inc_quo
mov a,c
add c
mov c,a
ret
divide: nop
CALL RESET
CALL READDASH8
call shift
call shift
call shift
call shift
call shift
call shift
call shift
call shift
MOV H, C
CALL RESETH
Rst 5
;code
start: nop
;SELECT OPERATION TYPE
LXI H, 9290h
MOV A, M
;SELECT OPERATION TO PERFORM
CALL SELECTOPERATION
Rst 5