-
Notifications
You must be signed in to change notification settings - Fork 6
/
omult31.a
110 lines (102 loc) · 1.81 KB
/
omult31.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
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
; omult31.a
; from TobyLobster
;
; 24 bit x 8 bit unsigned multiply, 24 bit result (high bytes)
;
; Average cycles: 168.90
; 2162 bytes
multiplier = $02
input0 = $03
input1 = $04
input2 = $05
result0 = $06
result1 = $07
result2 = $08
* = $0200
; Tables must be aligned to page boundary
square1_low
!for i, 0, 511 {
!byte <((i*i)/4)
}
square1_high
!for i, 0, 511 {
!byte >((i*i)/4)
}
square2_low
!for i, 0, 511 {
!byte <(((i-255)*(i-255))/4)
}
square2_high
!for i, 0, 511 {
!byte >(((i-255)*(i-255))/4)
}
; On Entry:
; input0,1,2: 24 bit multiplicand
; t: 8 bit multipler
; On Exit:
; output0,1,2: 24 bit result
mul24x8
lda multiplier
sta mult_internal1
sta mult_internal5
sta mult_internal9
sta mult_internal3
sta mult_internal7
sta mult_internal11
eor #$ff
sta mult_internal2
sta mult_internal6
sta mult_internal10
sta mult_internal4
sta mult_internal8
sta mult_internal12
ldx input0
sec
mult_internal1 = * + 1
lda square1_low,x
mult_internal2 = * + 1
sbc square2_low,x
mult_internal3 = * + 1
lda square1_high,x
mult_internal4 = * + 1
sbc square2_high,x
sta result0
ldx input1
sec
mult_internal5 = * + 1
lda square1_low,x
mult_internal6 = * + 1
sbc square2_low,x
tay
mult_internal7 = * + 1
lda square1_high,x
mult_internal8 = * + 1
sbc square2_high,x
sta result1
tya
clc
adc result0
sta result0
bcc +
inc result1
+
ldx input2
sec
mult_internal9 = * + 1
lda square1_low,x
mult_internal10 = * + 1
sbc square2_low,x
tay
mult_internal11 = * + 1
lda square1_high,x
mult_internal12 = * + 1
sbc square2_high,x
sta result2
tya
clc
adc result1
sta result1
bcc +
inc result2
+
rts