-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiv32.s
47 lines (42 loc) · 934 Bytes
/
div32.s
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
; N and R must be adjacent
; Zero-Page ; INPUT ; OUPUT
T :?= $19
D :?= $EB ; / d ;
N :?= $F8 ; n ; q = n/d
R :?= $FC ; 0 ; r = q - (n/d)*d
BYTE = 4
.if DIRECT
* = $BC80
.fi
; init R = 0
ldy #0
.for i in range(BYTE)
sty R+i
.next
; main loop: 32 iterations
ldx #8*BYTE
; Shift high bit of N into R
; N LSB = 0 (clc) and will be 1
; if INC N below
; N high bit enters in R low
LOOP clc
.for i in range(2*BYTE)
rol N+i
.next
; T = R - D on 32 bits
sec
.for i in range(BYTE)
lda R+i
sbc D+i
sta T+i
.next
blt NEXT ; R < D -> next
inc N ; N LSB 0->1
; Update R <- T
.for i in range(BYTE)
lda T+i
sta R+i
.next
NEXT dex ; next bit
bne LOOP ; if any
rts