-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.6502
146 lines (144 loc) · 1.55 KB
/
math.6502
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
\***************************************************************************
\
\ math.6502 - 32-bit Integer Arithmetic
\
\ Copyright (C) Charles Reilly 2023
\
\ This file is licensed under the GNU General Public License version 3
\
\***************************************************************************
.zero_other
LDA #0
STA other
STA other+1
STA other+2
STA other+3
RTS
.and_acc
LDA acc
AND other
STA acc
LDA acc+1
AND other+1
STA acc+1
LDA acc+2
AND other+2
STA acc+2
LDA acc+3
AND other+3
STA acc+3
RTS
.not_acc
LDA acc
EOR #&FF
STA acc
LDA acc+1
EOR #&FF
STA acc+1
LDA acc+2
EOR #&FF
STA acc+2
LDA acc+3
EOR #&FF
STA acc+3
RTS
.xor_acc
LDA acc
EOR other
STA acc
LDA acc+1
EOR other+1
STA acc+1
LDA acc+2
EOR other+2
STA acc+2
LDA acc+3
EOR other+3
STA acc+3
RTS
.add_acc
CLC
LDA acc
ADC other
STA acc
LDA acc+1
ADC other+1
STA acc+1
LDA acc+2
ADC other+2
STA acc+2
LDA acc+3
ADC other+3
STA acc+3
RTS
.left_rotate
LDA acc+3
ROL a
ROL acc
ROL acc+1
ROL acc+2
ROL acc+3
RTS
.right_rotate
LDA acc
ROR A
ROR acc+3
ROR acc+2
ROR acc+1
ROR acc
RTS
.mul16
{
LDA acc
STA other+2
LDA acc+1
STA other+3
LDA #0
STA acc
STA acc+1
LDX #16
.mul16_loop
LSR other+1
ROR other
BCC low_clear
LDA acc
CLC
ADC other+2
STA acc
LDA acc+1
ADC other+3
STA acc+1
.low_clear
ASL other+2
ROL other+3
DEX
BNE mul16_loop
RTS
}
.mul32
{
LDX #3
.copy_zero
LDA acc,X
STA scratch,X
LDA #0
STA acc,X
DEX
BPL copy_zero
LDX #32
.mul32_loop
LSR scratch+3
ROR scratch+2
ROR scratch+1
ROR scratch
BCC low_clear
JSR add_acc
.low_clear
ASL other
ROL other+1
ROL other+2
ROL other+3
DEX
BNE mul32_loop
RTS
}