annotate src/int.s @ 82:9a4e2364a966

Fix logic in int32_mul and overflow integer multiply to floating point It seems logical to allow integer multiplication to overflow to floating point. If this turns out to be unfortunate, it can be changed. In this update, 32 bit integer multiplication will overflow to floating point.
author William Astle <lost@l-w.ca>
date Sat, 07 Oct 2023 13:39:25 -0600
parents fbc14509955a
children a492441bfc56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
1 *pragmapush list
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
2 *pragma list
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
4 ; 32 bit integer handling package.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
5 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
6 ; Negate a 32 bit integer in (X); done by subtracting it from zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
7 int32_neg ldd zero ; subtract low word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
8 subd val.int+2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
9 std val.int+2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
10 ldd zero ; and now the high word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
11 sbcb val.int+1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
12 sbca val.int,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
13 std val.int,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
14 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
16 ; 32 bit integer addition (X) + (U) -> (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
17 int32_add ldd val.int+2,x ; do low word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
18 addd val.int+2,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
19 std val.int+2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
20 ldd val.int,x ; and the high word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
21 adcb val.int+1,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
22 adca val.int,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
23 std val.int,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
24 bvc int32_add0 ; raise overflow if needed
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
25 OVERROR2 jmp OVERROR
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
27 ; 32 bit integer subtraction (X) - (U) -> (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
28 int32_sub ldd val.int+2,x ; do low word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
29 subd val.int+2,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
30 std val.int+2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
31 ldd val.int,x ; and the high word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
32 sbcb val.int+1,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
33 sbca val.int,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
34 std val.int,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
35 bvs OVERROR2 ; raise overflow if needed
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
36 int32_add0 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
38 ; Signed 32 bit integer multiply (X) * (U) -> (Y), overflow if exceeds signed 32 bit range
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
39 int32_mul ldd val.int+2,x ; copy left operand to temporary
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
40 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
41 ldd val.int,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
42 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
43 eora val.int,u ; set sign bit in A if signs differ
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
44 pshs a ; save result sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
45 ldd val.int+2,u ; copy right operand to temporary
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
46 std fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
47 ldd val.int,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
48 std fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
49 bpl int32_mul0 ; brif right operand is positive
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
50 ldd zero ; negate right operand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
51 subd fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
52 std fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
53 ldd zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
54 sbcb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
55 sbca fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
56 std fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
57 int32_mul0 lda fpa0+fps.sig ; is left operand negative?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
58 bpl int32_mul1 ; brif not
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
59 ldd zero ; negate left operand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
60 subd fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
61 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
62 ldd zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
63 sbcb fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
64 sbca fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
65 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
66 int32_mul1 bsr util_mul32 ; do the actual multiplication
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
67 ldb fpa0extra ; are upper bits all zero?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
68 orb fpa0extra1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
69 orb fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
70 orb fpa0extra3
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
71 bne int32_mul4 ; brif not - overflow to floating point
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
72 ldb fpa0extra4 ; is bit 31 set?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
73 bpl int32_mul2 ; brif not - no overflow
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
74 lda ,s ; negative result wanted?
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
75 bpl int32_mul4 ; brif not - overflow to floating point
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
76 andb #0x7f ; lose extra sign bit
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
77 orb fpa0extra2 ; "or" in other bytes to see if all but bit 31 are zero
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
78 orb fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
79 orb fpa0extra7
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
80 bne int32_mul4 ; brif any nonzero bits - we overflowed maximum negative number
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
81 int32_mul2 ldb ,s+ ; do we want a negative result?
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
82 bpl int32_mul3 ; brif not - don't negate result
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
83 ldd zero ; negate result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
84 subd fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
85 std fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
86 ldd zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
87 sbcb fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
88 sbca fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
89 std fpa0extra4
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
90 int32_mul3 ldd fpa0extra4 ; copy result to destination
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
91 std val.int,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
92 ldd fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
93 std val.int+2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
94 rts
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
95 int32_mul4 puls b ; get back desired sign
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
96 sex ; set proper sign for floating point result
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
97 ldx #fpa0extra ; point to 64 bit unsigned result
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
98 jmp fps_fromuint64s ; go convert to floating point using the sign in A
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
100 ; 32 bit multiply.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
101 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
102 ; Significands of fpa0 and fpa1, treated as unsigned, are multiplied with the product being stored in the fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
103 ; memory locations.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
104 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
105 ; The agorithm is simply this: zero out the result, then multiply fpa0 by each byte of fpa1 and then add the result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
106 ; to the result location. This yields a 64 bit product which is somewhat wasteful.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
107 util_mul32 ldd zero ;* zero out result bits; low 16 bits don't need to be cleared and
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
108 stb fpa0extra3 ;* upper 24 bits also don't
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
109 std fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
110 ldb fpa1+fps.sig+3 ; multiply by low byte of fpa1 - no carries possible for this iteration
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
111 lda fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
112 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
113 std fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
114 ldb fpa1+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
115 lda fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
116 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
117 addd fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
118 std fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
119 ldb fpa1+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
120 lda fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
121 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
122 addd fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
123 std fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
124 ldb fpa1+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
125 lda fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
126 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
127 addd fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
128 std fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
129 ; Now we potentially have cascading carries at every stage; it makes more sense to handle those in a separate
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
130 ; addition pass after each partial calculation. The partial calculations are identical to above. This is completely
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
131 ; unrolled for speed.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
132 ldd zero ; zero out extra work bytes
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
133 std fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
134 stb fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
135 ldb fpa1+fps.sig+2 ; multiply by second low byte of fpa1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
136 lda fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
137 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
138 std fpa0extra11
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
139 ldb fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
140 lda fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
141 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
142 addd fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
143 std fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
144 ldb fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
145 lda fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
146 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
147 addd fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
148 std fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
149 ldb fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
150 lda fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
151 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
152 addd fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
153 std fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
154 ldd fpa0extra11 ; add to partial product (shifted left 8 bits)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
155 addd fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
156 std fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
157 ldd fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
158 adcb fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
159 adca fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
160 std fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
161 ldb #0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
162 adcb fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
163 stb fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
164 ldd zero ; and do it all again for next byte of fpa1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
165 std fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
166 stb fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
167 ldb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
168 lda fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
169 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
170 std fpa0extra11
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
171 ldb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
172 lda fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
173 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
174 addd fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
175 std fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
176 ldb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
177 lda fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
178 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
179 addd fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
180 std fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
181 ldb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
182 lda fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
183 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
184 addd fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
185 std fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
186 ldd fpa0extra11
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
187 addd fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
188 std fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
189 ldd fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
190 adcb fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
191 adca fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
192 std fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
193 ldb #0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
194 adcb fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
195 stb fpa0extra1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
196 ldd zero ; and the final sequence with the fpa1 high byte
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
197 std fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
198 stb fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
199 ldb fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
200 lda fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
201 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
202 std fpa0extra11
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
203 ldb fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
204 lda fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
205 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
206 addd fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
207 std fpa0extra10
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
208 ldb fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
209 lda fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
210 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
211 addd fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
212 std fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
213 ldb fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
214 lda fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
215 mul
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
216 addd fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
217 std fpa0extra8
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
218 ldd fpa0extra11
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
219 addd fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
220 std fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
221 ldd fpa0extra9
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
222 adcb fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
223 adca fpa0extra1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
224 std fpa0extra1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
225 ldb #0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
226 adcb fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
227 stb fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
228 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
230 ; 32 bit division, integer only, truncate fraction without rounding. Note that there is exactly one case where integer
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
231 ; division can overflow: dividing -0x80000000 by -1 which yields 0x80000000. All other cases reduce the magnitude.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
232 int32_div ldd val.int+2,x ; copy left operand to temporary
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
233 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
234 ldd val.int,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
235 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
236 eora val.int,u ; set sign bit in A if signs differ
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
237 pshs a ; save result sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
238 ldd val.int+2,u ; copy right operand to temporary
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
239 std fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
240 ldd val.int,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
241 std fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
242 bpl int32_div0 ; brif right operand is positive
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
243 ldd zero ; negate right operand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
244 subd fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
245 std fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
246 ldd zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
247 sbcb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
248 sbca fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
249 std fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
250 int32_div0 lda fpa0+fps.sig ; is left operand negative?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
251 bpl int32_div1 ; brif not
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
252 ldd zero ; negate left operand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
253 subd fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
254 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
255 ldd zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
256 sbcb fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
257 sbca fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
258 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
259 int32_div1 ldb fpa1+fps.sig ; check for division by zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
260 orb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
261 orb fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
262 orb fpa1+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
263 lbne DIV0ERROR ; brif division by zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
264 bsr util_div32 ; do the actual division
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
265 lda ,s+ ; get desired sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
266 bmi int32_div2 ; brif want negative - we can't overflow in that case
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
267 ldb fpa0extra ; get high byte of result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
268 lbmi OVERROR2 ; brif we ended up with 0x80000000 positive
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
269 bra int32_div3 ; go return result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
270 int32_div2 ldd zero ; negate result to correct sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
271 subd fpa0extra+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
272 std fpa0extra+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
273 ldd zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
274 sbcb fpa0extra+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
275 sbca fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
276 std fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
277 int32_div3 ldd fpa0extra ; copy result to destination
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
278 std val.int,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
279 ldd fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
280 std val.int+2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
281 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
283 ; Divide 32 bit integer in fpa0 significand by 32 bit integer in fpa1 significand, both treated as unsigned. Leave
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
284 ; quotient at fpa0extra...fpa0extra3 and remainder at fpa0extra4...fpa0extra7; does not check for division by zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
285 ; which will result in a quotient of 0xffffffff and a remainder will be the dividend. It will not get suck in a loop.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
286 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
287 ; Algorithm is basically pencil and paper long division. We check to see if the divisor "goes" at each step by doing
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
288 ; a trial subtraction without saving the result. If it doesn't go, we just loop around again. If it does go, we stash
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
289 ; a 1 bit in the quotient and actually do the subtraction. Then go loop around again. Doing it this way rather than
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
290 ; with an actual subtraction and then undoing it with addition saves two store instructions on the comparison saves
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
291 ; having to do a restore in the no-go case which is going to be quite common with values whose upper bits are
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
292 ; mostly zeroes, thus it makes the operations faster in that case, for integers. (Floating point is a different
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
293 ; problem.)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
294 util_div32 ldd fpa0+fps.sig+2 ; copy dividend to result location
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
295 std fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
296 ldd fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
297 std fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
298 ldb #32 ; do 32 bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
299 stb fpa0+fps.exp ; save counter somewhere because we don't have enough registers
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
300 ldd zero ; zero out remainder
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
301 std fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
302 std fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
303 util_div32a lsl fpa0extra3 ; shift dividend residue into remainder
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
304 rol fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
305 rol fpa0extra1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
306 rol fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
307 rol fpa0extra7
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
308 rol fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
309 rol fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
310 rol fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
311 ldd fpa0extra6 ; now subtract divisor from remainder
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
312 subd fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
313 ldd fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
314 sbcb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
315 sbca fpa1+fps.sig
81
fbc14509955a Fix comments on 32 bit division routine
William Astle <lost@l-w.ca>
parents: 80
diff changeset
316 bcs util_div32b ; brif it doesn't go - don't subtract or set bit
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
317 inc fpa0extra3 ; set quotient bit
81
fbc14509955a Fix comments on 32 bit division routine
William Astle <lost@l-w.ca>
parents: 80
diff changeset
318 ldd fpa0extra6 ; actually do the subtraction
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
319 subd fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
320 std fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
321 ldd fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
322 sbcb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
323 sbca fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
324 std fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
325 util_div32b dec fpa0+fps.exp ; done all 32 bits?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
326 bne util_div32a ; do another
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
327 *pragmapop list