annotate src/int.s @ 113:0aac26453849

Actually implement the 32 bit integer division algorithm correctly
author William Astle <lost@l-w.ca>
date Tue, 26 Dec 2023 23:37:45 -0700
parents 98b0646360e1
children
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
97
b375a38b2b1a Fix initialization error in integer to ascii conversion
William Astle <lost@l-w.ca>
parents: 85
diff changeset
12 ldd #0xa00 ; do 10 digits, no nonzero seen yet
b375a38b2b1a Fix initialization error in integer to ascii conversion
William Astle <lost@l-w.ca>
parents: 85
diff changeset
13 std fpaextra ; save digit counts
85
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.
108
b1958992a66a Properly initialize result for integer multiplication
William Astle <lost@l-w.ca>
parents: 97
diff changeset
207 util_mul32 ldd zero ;* zero out result bits; low 16 bits don't need to be cleared
b1958992a66a Properly initialize result for integer multiplication
William Astle <lost@l-w.ca>
parents: 97
diff changeset
208 std fpaextra
b1958992a66a Properly initialize result for integer multiplication
William Astle <lost@l-w.ca>
parents: 97
diff changeset
209 std fpaextra+2
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
210 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
211 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
212 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
213 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
214 std fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
215 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
216 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
217 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
218 addd fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
219 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
220 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
221 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
222 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
223 addd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
224 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
225 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
226 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
227 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
228 addd fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
229 std fpaextra+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
230 ; 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
231 ; 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
232 ; unrolled for speed.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
233 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
234 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
235 stb fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
236 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
237 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
238 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
239 std fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
240 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
241 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
242 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
243 addd fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
244 std fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
245 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
246 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
247 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
248 addd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
249 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
250 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
251 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
252 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
253 addd fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
254 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
255 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
256 addd fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
257 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
258 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
259 adcb fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
260 adca fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
261 std fpaextra+3
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
262 ldb #0
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
263 adcb fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
264 stb fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
265 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
266 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
267 stb fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
268 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
269 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
270 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
271 std fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
272 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
273 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
274 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
275 addd fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
276 std fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
277 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
278 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
279 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
280 addd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
281 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
282 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
283 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
284 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
285 addd fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
286 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
287 ldd fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
288 addd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
289 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
290 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
291 adcb fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
292 adca fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
293 std fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
294 ldb #0
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
295 adcb fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
296 stb fpaextra+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
297 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
298 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
299 stb fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
300 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
301 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
302 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
303 std fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
304 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
305 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
306 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
307 addd fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
308 std fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
309 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
310 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
311 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
312 addd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
313 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
314 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
315 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
316 mul
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
317 addd fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
318 std fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
319 ldd fpaextra+11
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
320 addd fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
321 std fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
322 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
323 adcb fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
324 adca fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
325 std fpaextra+1
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
326 ldb #0
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
327 adcb fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
328 stb fpaextra
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
329 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
331 ; 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
332 ; 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
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
357 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
358 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
359 std fpa0+fpa.sig
112
98b0646360e1 Fix division by zero detection to actually work for integer division
William Astle <lost@l-w.ca>
parents: 111
diff changeset
360 int32_div1 ldd fpa1+fpa.sig ; is MSW zero?
98b0646360e1 Fix division by zero detection to actually work for integer division
William Astle <lost@l-w.ca>
parents: 111
diff changeset
361 bne int32_div1a ; brif not - not division by zero
98b0646360e1 Fix division by zero detection to actually work for integer division
William Astle <lost@l-w.ca>
parents: 111
diff changeset
362 ldd fpa1+fpa.sig+2
98b0646360e1 Fix division by zero detection to actually work for integer division
William Astle <lost@l-w.ca>
parents: 111
diff changeset
363 lbeq DIV0ERROR ; brif LSW is zero - division by zero
98b0646360e1 Fix division by zero detection to actually work for integer division
William Astle <lost@l-w.ca>
parents: 111
diff changeset
364 int32_div1a bsr util_div32 ; do the actual division
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
365 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
366 bmi int32_div2 ; brif want negative - we can't overflow in that case
112
98b0646360e1 Fix division by zero detection to actually work for integer division
William Astle <lost@l-w.ca>
parents: 111
diff changeset
367 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
368 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
369 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
370 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
371 subd fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
372 std fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
373 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
374 sbcb fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
375 sbca fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
376 std fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
377 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
378 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
379 ldd fpaextra+2
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
380 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
381 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
383 ; 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
384 ; 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
385 ; 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
386 ;
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
387 ; Uses a 96 bit temporary at fpaextra. The high 32 bits are the result and the mid 32 bits will be the remainder. The
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
388 ; remaining 32 bits are used to avoid modifing the fpa0 significand. The extra 4 bytes could be avoided by simply
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
389 ; clobbering the fpa0 significand.
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
390 ;
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
391 ; The algorithm is basically the pencil and paper long division algorithm. First, the dividend is shifted left one
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
392 ; bit into the remainder. If a carry occurs from that, the subtraction will succeed. If not, do a trial subtraction
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
393 ; which is just the subtraction without saving the result. If that results in a carry, then the divisor doesn't "go"
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
394 ; at this bit position so the quotient bit will be zero. If there is no carry here or there was a carry on the shift,
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
395 ; it does "go" so the quotient bit will be one. If it went, actually do the subtraction. In either event, shift the
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
396 ; quotient bit into the accumulated quotient. Do this for all 32 bits.
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
397 ;
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
398 ; The carry has to be checked on the shift to simulate doing what is basically a 33 bit subtraction.
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
399 util_div32 ldd fpa0+fpa.sig+2 ; copy dividend to result location
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
400 std fpaextra+10
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
401 ldd fpa0+fpa.sig
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
402 std fpaextra+8
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
403 ldb #32 ; do 64 bits - will give us a remainder
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
404 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
405 ldd zero ; zero out remainder
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
406 std fpaextra
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
407 std fpaextra+2
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
408 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
409 std fpaextra+6
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
410 util_div32a lsl fpaextra+11 ; shift residue and remainder over
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
411 rol fpaextra+10
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
412 rol fpaextra+9
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
413 rol fpaextra+8
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
414 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
415 rol fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
416 rol fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
417 rol fpaextra+4
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
418 pshs cc ; save "goes" status from shift
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
419 bcs util_div32b ; brif it definitely goes
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
420 ldd fpaextra+6 ; do a trial subtraction
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
421 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
422 ldd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
423 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
424 sbca fpa1+fpa.sig
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
425 bcs util_div32c ; brif it doesn't go - goes status on stack is right
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
426 inc ,s ; set "C" on the stack
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
427 util_div32b ldd fpaextra+6 ; actually do the subtraction
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
428 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
429 std fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
430 ldd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
431 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
432 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
433 std fpaextra+4
113
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
434 util_div32c puls cc ; get back "goes" status
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
435 rol fpaextra+3 ; shift quotient over and put the new bit in
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
436 rol fpaextra+2
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
437 rol fpaextra+1
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
438 rol fpaextra
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
439 dec fpa0+fpa.exp ; done 32 bits?
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
440 bne util_div32a ; brif not - handle another bit position
0aac26453849 Actually implement the 32 bit integer division algorithm correctly
William Astle <lost@l-w.ca>
parents: 112
diff changeset
441 rts
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
442 *pragmapop list