-
Notifications
You must be signed in to change notification settings - Fork 6
/
mult82.a
63 lines (58 loc) · 948 Bytes
/
mult82.a
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
; mult82.a
; from Retro Software (2008): http://www.retrosoftware.co.uk/wiki/index.php?title=Fast_multiplication_routines
;
; 8 bit x 8 bit unsigned multiply
; Average cycles: 67.24
; 827 bytes
num1 = $02
num2 = $03
result = $04 ; 2 bytes
* = $0200
; Align tables to start of page for speed
sqrlo
!for i, 0, 255 {
!byte <((i*i)/4)
}
sqrhi256
!for i, 0, 255 {
!byte >((i*i)/4)
}
sqrhi512
!for i, 0, 255 {
!byte >(((i+256)*(i+256))/4)
}
mult
sec
lda num1
sbc num2
bcs positive
eor #255
adc #1
positive
tay
clc
lda num1
adc num2
tax
bcs morethan256
lda sqrhi256,X
sta result+1
lda sqrlo,X
sec
bcs lessthan256
morethan256
lda sqrhi512,X
sta result+1
txa
and #1
beq skip
lda #$80
skip
eor sqrlo,X
lessthan256
sbc sqrlo,Y
sta result
lda result+1
sbc sqrhi256,Y
sta result+1
rts