We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 26954ac commit 2960085Copy full SHA for 2960085
1 file changed
src/interp/div.asm
@@ -85,6 +85,9 @@ x_pos: sta tmp3
85
ldy #16
86
lda #0
87
sta tmp2+1
88
+ ; Detect we are dividing by numbers < 256 and use a faster algorithm.
89
+ ; The assumption is that smaller divisors are much more common than
90
+ ; larger ones, so this pays off.
91
ldx tmp1+1
92
beq udiv16x8
93
@@ -111,11 +114,15 @@ L1: txa
111
114
rts
112
115
113
116
udiv16x8:
- ldx tmp1
- beq L0
117
+; This is needed to return modulo > 255 on division by 0. We could also
118
+; set an error flag, but it is simpler to just return an invalid value.
119
+; ldx tmp1
120
+; beq L0
121
L2: asl tmp3
122
rol tmp3+1
123
rol
124
+ ; When the current modulo is > 255, we always need to subtract the
125
+ ; divisor, and we already have C=1.
126
bcs L3
127
128
cmp tmp1
0 commit comments