-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmult83.a
More file actions
62 lines (57 loc) · 987 Bytes
/
mult83.a
File metadata and controls
62 lines (57 loc) · 987 Bytes
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
; mult83.a
; from Retro Software: http://www.retrosoftware.co.uk/wiki/index.php?title=Fast_multiplication_routines
;
; 8 bit x 8 bit unsigned multiply, 16 bit result
; Average cycles: 56.00
; 1079 bytes
num1 = $02
num2 = $03
result = $04 ; 2 bytes
* = $0200
; Align tables to start of page for speed
sqrlo256
!for i, 0, 255 {
!byte <((i*i)/4)
}
sqrhi256
!for i, 0, 255 {
!byte >((i*i)/4)
}
sqrlo512
!for i, 0, 255 {
!byte <(((i+256)*(i+256))/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
sec
lda sqrlo256,X
sbc sqrlo256,Y
sta result
lda sqrhi256,X
sbc sqrhi256,Y
sta result+1
rts
morethan256
lda sqrlo512,X
sbc sqrlo256,Y
sta result
lda sqrhi512,X
sbc sqrhi256,Y
sta result+1
rts