Skip to content

Commit 55615c7

Browse files
committed
Merge branch 'main' of https://github.com/davidly/ntvcm
2 parents 6e52098 + 77f2c72 commit 55615c7

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

ttt/asm/e.asm

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ org 100h
5656
; n := n - 1;
5757
; end;
5858

59-
; register c is n. hl is a[]. b is a constant 1, a is a constant 0
59+
; register c is n. hl is a[]. b is a constant 1
6060

61-
mvi a, 0
6261
mvi b, 1
6362
mvi c, DIGITS - 1
6463
lxi h, array + DIGITS - 1
@@ -67,7 +66,6 @@ org 100h
6766
mov m, b
6867
dcx h
6968
dcr c
70-
cmp c
7169
jnz ainit
7270

7371
; a[ 1 ] := 2;
@@ -102,7 +100,7 @@ org 100h
102100
mov m, a ; a[ n ] := x MOD n;
103101

104102
dcx h ; make hl point to a[ n - 1 ]
105-
mov e, m ; put a[ n - 1 ] in de
103+
mov e, m ; put a[ n - 1 ] in de
106104
mvi d, 0
107105
mov h, d ; put the typically smaller mul argument (10) in hl for better performance
108106
mvi l, 10
@@ -111,8 +109,6 @@ org 100h
111109
dad d ; add the two parts together. x (aka hl) := (mul result + div result)
112110

113111
dcr c ; n := n - 1;
114-
xra a
115-
cmp c
116112
jnz innerloop ; if n isn't 0 then loop again
117113

118114
call PrintNumber ; show the next digit(s) of e
@@ -219,47 +215,31 @@ PUTHL: ; print the signed 16-bit number in HL
219215
; unsigned multiply de by hl, result in hl
220216
umul:
221217
mov a, l
222-
cpi 0
223-
jnz umul$notzero
224-
mov a, h
225-
cpi 0
226-
jnz umul$notzero
227-
ret
228-
umul$notzero:
229-
push b ! push d
230-
push h
231-
pop b
218+
ora h
219+
rz
220+
push b
221+
mov b, h
222+
mov c, l
232223
lxi h, 0
233-
shld mulTmp
234224
umul$loop:
235225
dad d
236-
jnc umul$done
237-
push h
238-
lhld mulTmp
239-
inx h
240-
shld mulTmp
241-
pop h
242-
umul$done:
243226
dcx b
244227
mov a, b
245228
ora c
246229
jnz umul$loop
247-
pop d ! pop b
230+
pop b
248231
ret
249232

250-
; unsigned divide de by hl, result in hl. remainder in divRem
233+
; unsigned divide de by hl, result in hl. remainder in divRem. divide by 0 not checked.
251234
udiv:
252-
xra a
253-
cmp e
254-
jnz udiv$notzero
255-
cmp d
235+
mov a, e
236+
ora d
256237
jnz udiv$notzero
257238
lxi h, 0
258239
shld divRem ; 0 mod x is 0
259240
ret
260-
261241
udiv$notzero:
262-
push b ! push d
242+
push b
263243
xchg
264244
lxi b, 0
265245
udiv$loop:
@@ -277,7 +257,7 @@ udiv:
277257
shld divRem
278258
mov l, c
279259
mov h, b
280-
pop d ! pop b
260+
pop b
281261
ret
282262

283263
NEGF: db 0 ; Space for negative flag
@@ -286,7 +266,6 @@ NUM: db '$' ; Space for number. cp/m strings end with a
286266
CRLF: db 13,10,0
287267
STRDONE: db 'done.', 13, 10, 0
288268

289-
MULTMP: dw 0
290269
DIVREM: dw 0
291270
ARRAY: ds DIGITS
292271

@@ -337,8 +316,8 @@ imul:
337316
call neg$hl
338317
call neg$de
339318
imul$notneg:
340-
push h
341-
pop b
319+
mov b, h
320+
mov c, l
342321
lxi h, 0
343322
shld mulTmp
344323
imul$loop:

0 commit comments

Comments
 (0)