-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath2.s
More file actions
108 lines (98 loc) · 1.92 KB
/
math2.s
File metadata and controls
108 lines (98 loc) · 1.92 KB
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
.SETCPU "6502"
.SEGMENT "OSCODE"
.EXPORT FDIV10
F0 = $90
F1 = $94
F2 = $98
FDIV10: ; multiply with 0.1
; argument is in F0
LDY #3
LDA F0+1 ; get argument mantissa
BPL FDPOS ; number is positive
SEC
NEGNU:
LDA F0,Y
EOR #$FF ; negate
ADC #0
STA F1,Y
DEY ; as long as y > 0
BNE NEGNU ; neg next mant. byte
JMP MULT01
FDPOS:
LDA F0,Y
STA F1,Y
DEY
BNE FDPOS
MULT01:
LDY #3
LDA F1,Y
STA F2,Y
DEY
BNE MULT01+2 ; copy F1 to F2
LDY #6
;************************** LOOP ****
MULTI:
JSR SHIFTM2
JSR MULTM2
JSR SHIFTM2
JSR SHIFTM2
JSR SHIFTM2
JSR MULTM2
DEY
BNE MULTI ; LOOP 6 TIMES
SEC
LDA F0
SBC #4 ; subtract 4 from exponent
STA F2 ; store exponent
LDA F2+1
AND #$80 ; carry from multi?
BEQ MULOK ; no, no correction
CLC
LDX #1
PHP
ROR5: ; shift all 24bit
PLP
ROR F2,X
INX
PHP
CPX #4
BNE ROR5
PLP
INC F2 ; increase exponent
MULOK:
LDA F0+1
BPL NUMPOS2
LDY #3
SEC
NEGNUM2:
LDA F2,Y
EOR #$FF ; negate
ADC #0
STA F2,Y
DEY ; as long as y > 0
BNE NEGNUM2 ; neg next mant. byte
NUMPOS2:
RTS
SHIFTM2:
CLC
LDX #1
PHP
ROR1:
PLP
ROR F1,X
INX
PHP
CPX #4
BNE ROR1 ; SHIFT RIGHT
PLP
RTS
MULTM2:
CLC
LDX #3
MULT02:
LDA F2,X
ADC F1,X
STA F2,X
DEX
BNE MULT02 ; ADD
RTS