annotate src/int.s @ 85:663d8e77b579

Implmement BCD floating point and update number parsing and printing Implements a BCD floating point system with 10 decimal digits of precistion and an exponent range of -63 to +63. Also include parsing integer and floating point values and printing them out.
author William Astle <lost@l-w.ca>
date Sun, 15 Oct 2023 22:15:36 -0600
parents a492441bfc56
children b375a38b2b1a
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
4 ; Convert a signed integer in val0 to a string in strbuff
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
5 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
6 ; The maximum size of a string generated here is 12 bytes representing 10 significant digits, a leading sign, and the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
7 ; trailing NUL.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
8 int_toascii ldu #strbuff+1 ; point to start of digits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
9 lda #0x20 ; default sign to space
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
10 sta -1,u
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
11 ldx #int_toascii5 ; point to digit constant table
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
12 ldd #10 ; do 10 digits, no nonzero seen yet
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
13 stb fpaextra ; save digit count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
14 ldd val0+val.int+2 ; copy to temporary accumulator
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
15 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
16 ldd val0+val.int
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
17 std fpaextra+2 ; (will set N if the number is negative)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
18 bpl int_toascii0 ; brif so
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
19 lda #'- ; negative sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
20 sta -1,u ; set sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
21 ldd zero ; negate the value
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
22 subd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
23 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
24 ldd zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
25 sbcb fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
26 sbca fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
27 std fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
28 int_toascii0 lda #0x2f ; initialize digit (account for inc below)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
29 sta ,u
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
30 int_toascii1 inc ,u ; bump digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
31 ldd fpaextra+4 ; subtract digit constnat
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
32 subd 2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
33 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
34 ldd fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
35 sbcb 1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
36 sbca ,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
37 std fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
38 bcc int_toascii1 ; brif we aren't at the right digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
39 ldd fpaextra+4 ; undo extra subtraction
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
40 addd 2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
41 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
42 ldd fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
43 adcb 1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
44 adca ,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
45 std fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
46 leax 4,x ; move to next constant
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
47 lda ,u ; get digit count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
48 cmpa #'0 ; is it zero?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
49 bne int_toascii2 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
50 lda fpaextra+1 ; get nonzero digit count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
51 beq int_toascii3 ; brif we haven't already got a nonzero - don't count the zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
52 int_toascii2 inc fpaextra+1 ; bump nonzero digit count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
53 leau 1,u ; move to next digit position
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
54 int_toascii3 dec fpaextra ; done all digits?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
55 bne int_toascii0 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
56 ldb fpaextra+1 ; did we have any nonzero digits?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
57 bne int_toascii4 ; brif so
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
58 leau 1,u ; move past the only zero in the output
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
59 int_toascii4 clr ,u ; NUL terminate the string
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
60 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
61 int_toascii5 fqb 1000000000 ; digit place values
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
62 fqb 100000000
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
63 fqb 10000000
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
64 fqb 1000000
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
65 fqb 100000
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
66 fqb 10000
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
67 fqb 1000
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
68 fqb 100
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
69 fqb 10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
70 fqb 1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
71 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
72 ; 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
73 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
74 ; 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
75 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
76 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
77 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
78 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
79 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
80 sbca val.int,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
81 std val.int,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
82 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
84 ; 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
85 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
86 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
87 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
88 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
89 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
90 adca val.int,u
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 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
93 OVERROR2 jmp OVERROR
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
95 ; 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
96 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
97 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
98 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
99 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
100 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
101 sbca val.int,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
102 std val.int,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
103 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
104 int32_add0 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
106 ; Fast multiply 32 bit at (X) by 10
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
107 ;
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
108 ; This will work for signed because the left shift will double it even if it is negative and V is set correctly after
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
109 ; left shifts. The add will have the same sign so the magnitude will still increase, not decrease.
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
110 uint32_mul10 ldd val.int,x ; make copy of original
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
111 ldu val.int+2,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
112 pshs d,u ; save original
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
113 lsl val.int+3,x ; shift left (times 2)
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
114 rol val.int+2,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
115 rol val.int+1,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
116 rol val.int,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
117 bvs OVERROR2 ; brif overflow
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
118 lsl val.int+3,x ; shift left (times 4)
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
119 rol val.int+2,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
120 rol val.int+1,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
121 rol val.int,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
122 bvs OVERROR2 ; brif overflow
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
123 ldd val.int+2,x ; add original (times 5)
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
124 addd 2,s
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
125 std val.int+2,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
126 puls d,u ; (get upper word and clean stack)
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
127 adcb val.int+1,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
128 adca val.int,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
129 std val.int,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
130 bvs OVERROR2 ; brif overflow
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
131 lsl val.int+3,x ; shift left again (times 10)
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
132 rol val.int+2,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
133 rol val.int+1,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
134 rol val.int,x
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
135 bvs OVERROR2 ; brif overflow
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
136 rts
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
138 ; 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
139 int32_mul ldd val.int+2,x ; copy left operand to temporary
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
140 std fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
141 ldd val.int,x
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
142 std fpa0+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
143 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
144 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
145 ldd val.int+2,u ; copy right operand to temporary
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
146 std fpa1+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
147 ldd val.int,u
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
148 std fpa1+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
149 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
150 ldd zero ; negate right operand
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
151 subd fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
152 std fpa1+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
153 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
154 sbcb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
155 sbca fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
156 std fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
157 int32_mul0 lda fpa0+fpa.sig ; is left operand negative?
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
158 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
159 ldd zero ; negate left operand
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
160 subd fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
161 std fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
162 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
163 sbcb fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
164 sbca fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
165 std fpa0+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
166 int32_mul1 bsr util_mul32 ; do the actual multiplication
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
167 ldb fpaextra ; are upper bits all zero?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
168 orb fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
169 orb fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
170 orb fpaextra+3
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
171 bne int32_mul4 ; brif not - overflow to floating point
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
172 ldb fpaextra+4 ; is bit 31 set?
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
173 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
174 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
175 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
176 andb #0x7f ; lose extra sign bit
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
177 orb fpaextra+2 ; "or" in other bytes to see if all but bit 31 are zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
178 orb fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
179 orb fpaextra+7
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 81
diff changeset
180 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
181 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
182 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
183 ldd zero ; negate result
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
184 subd fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
185 std fpaextra+6
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
186 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
187 sbcb fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
188 sbca fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
189 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
190 int32_mul3 ldd fpaextra+4 ; 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
191 std val.int,y
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
192 ldd fpaextra+6
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
193 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
194 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
195 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
196 sex ; set proper sign for floating point result
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
197 ldx #fpaextra ; point to 64 bit unsigned result
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
198 ; 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
199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
200 ; 32 bit multiply.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
201 ;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
202 ; Significands of fpa0 and fpa1, treated as unsigned, are multiplied with the product being stored in the fpaextra
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
203 ; memory locations.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
204 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
205 ; 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
206 ; 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
207 util_mul32 ldd zero ;* zero out result bits; low 16 bits don't need to be cleared and
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
208 stb fpaextra+3 ;* upper 24 bits also don't
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
209 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
210 ldb fpa1+fpa.sig+3 ; multiply by low byte of fpa1 - no carries possible for this iteration
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
211 lda fpa0+fpa.sig+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
212 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
213 std fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
214 ldb fpa1+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
215 lda fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
216 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
217 addd fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
218 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
219 ldb fpa1+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
220 lda fpa0+fpa.sig+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
221 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
222 addd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
223 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
224 ldb fpa1+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
225 lda fpa0+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
226 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
227 addd fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
228 std fpaextra+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
229 ; 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
230 ; 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
231 ; unrolled for speed.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
232 ldd zero ; zero out extra work bytes
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
233 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
234 stb fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
235 ldb fpa1+fpa.sig+2 ; multiply by second low byte of fpa1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
236 lda fpa0+fpa.sig+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
237 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
238 std fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
239 ldb fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
240 lda fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
241 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
242 addd fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
243 std fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
244 ldb fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
245 lda fpa0+fpa.sig+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
246 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
247 addd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
248 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
249 ldb fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
250 lda fpa0+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
251 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
252 addd fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
253 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
254 ldd fpaextra+11 ; add to partial product (shifted left 8 bits)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
255 addd fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
256 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
257 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
258 adcb fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
259 adca fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
260 std fpaextra+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
261 ldb #0
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
262 adcb fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
263 stb fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
264 ldd zero ; and do it all again for next byte of fpa1
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
265 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
266 stb fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
267 ldb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
268 lda fpa0+fpa.sig+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
269 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
270 std fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
271 ldb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
272 lda fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
273 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
274 addd fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
275 std fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
276 ldb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
277 lda fpa0+fpa.sig+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
278 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
279 addd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
280 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
281 ldb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
282 lda fpa0+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
283 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
284 addd fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
285 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
286 ldd fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
287 addd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
288 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
289 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
290 adcb fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
291 adca fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
292 std fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
293 ldb #0
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
294 adcb fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
295 stb fpaextra+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
296 ldd zero ; and the final sequence with the fpa1 high byte
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
297 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
298 stb fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
299 ldb fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
300 lda fpa0+fpa.sig+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
301 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
302 std fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
303 ldb fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
304 lda fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
305 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
306 addd fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
307 std fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
308 ldb fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
309 lda fpa0+fpa.sig+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
310 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
311 addd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
312 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
313 ldb fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
314 lda fpa0+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
315 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
316 addd fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
317 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
318 ldd fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
319 addd fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
320 std fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
321 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
322 adcb fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
323 adca fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
324 std fpaextra+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
325 ldb #0
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
326 adcb fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
327 stb fpaextra
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
328 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
330 ; Integer divide (X) by 10 *in place*
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
331 int32_const10 fqb 10 ; integer constant 10
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
332 int32_div10 ldu #int32_const10 ; point to integer constant 10
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
333 leay ,x ; point to output location
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
334 ; fall through to integer division
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
336 ; 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
337 ; 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
338 int32_div ldd val.int+2,x ; copy left operand to temporary
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
339 std fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
340 ldd val.int,x
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
341 std fpa0+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
342 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
343 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
344 ldd val.int+2,u ; copy right operand to temporary
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
345 std fpa1+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
346 ldd val.int,u
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
347 std fpa1+fpa.sig
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
348 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
349 ldd zero ; negate right operand
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
350 subd fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
351 std fpa1+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
352 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
353 sbcb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
354 sbca fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
355 std fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
356 int32_div0 lda fpa0+fpa.sig ; is left operand negative?
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
357 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
358 ldd zero ; negate left operand
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
359 subd fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
360 std fpa0+fpa.sig+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
361 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
362 sbcb fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
363 sbca fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
364 std fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
365 int32_div1 ldb fpa1+fpa.sig ; check for division by zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
366 orb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
367 orb fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
368 orb fpa1+fpa.sig+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
369 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
370 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
371 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
372 bmi int32_div2 ; brif want negative - we can't overflow in that case
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
373 ldb fpaextra ; get high byte of result
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
374 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
375 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
376 int32_div2 ldd zero ; negate result to correct sign
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
377 subd fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
378 std fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
379 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
380 sbcb fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
381 sbca fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
382 std fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
383 int32_div3 ldd fpaextra ; 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
384 std val.int,y
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
385 ldd fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
386 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
387 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
389 ; Divide 32 bit integer in fpa0 significand by 32 bit integer in fpa1 significand, both treated as unsigned. Leave
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
390 ; quotient at fpaextra...fpaextra+3 and remainder at fpaextra+4...fpaextra+7; does not check for division by zero
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
391 ; 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
392 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
393 ; 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
394 ; 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
395 ; 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
396 ; 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
397 ; 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
398 ; 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
399 ; problem.)
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
400 util_div32 ldd fpa0+fpa.sig+2 ; copy dividend to result location
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
401 std fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
402 ldd fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
403 std fpaextra+4
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
404 ldb #32 ; do 32 bits
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
405 stb fpa0+fpa.exp ; save counter somewhere because we don't have enough registers
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
406 ldd zero ; zero out remainder
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
407 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
408 std fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
409 util_div32a lsl fpaextra+3 ; shift dividend residue into remainder
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
410 rol fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
411 rol fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
412 rol fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
413 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
414 rol fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
415 rol fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
416 rol fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
417 ldd fpaextra+6 ; now subtract divisor from remainder
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
418 subd fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
419 ldd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
420 sbcb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
421 sbca fpa1+fpa.sig
81
fbc14509955a Fix comments on 32 bit division routine
William Astle <lost@l-w.ca>
parents: 80
diff changeset
422 bcs util_div32b ; brif it doesn't go - don't subtract or set bit
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
423 inc fpaextra+3 ; set quotient bit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
424 ldd fpaextra+6 ; actually do the subtraction
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
425 subd fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
426 std fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
427 ldd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
428 sbcb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
429 sbca fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
430 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
431 util_div32b dec fpa0+fpa.exp ; done all 32 bits?
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
432 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
433 *pragmapop list