changeset 112:98b0646360e1

Fix division by zero detection to actually work for integer division
author William Astle <lost@l-w.ca>
date Tue, 26 Dec 2023 21:50:09 -0700
parents b10f6c8979a5
children 0aac26453849
files src/int.s
diffstat 1 files changed, 6 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/int.s	Tue Dec 26 21:44:10 2023 -0700
+++ b/src/int.s	Tue Dec 26 21:50:09 2023 -0700
@@ -357,15 +357,14 @@
                 sbcb fpa0+fpa.sig+1
                 sbca fpa0+fpa.sig
                 std fpa0+fpa.sig
-int32_div1      ldb fpa1+fpa.sig                ; check for division by zero
-                orb fpa1+fpa.sig+1
-                orb fpa1+fpa.sig+2
-                orb fpa1+fpa.sig+3
-                lbne DIV0ERROR                  ; brif division by zero
-                bsr util_div32                  ; do the actual division
+int32_div1      ldd fpa1+fpa.sig                ; is MSW zero?
+                bne int32_div1a                 ; brif not - not division by zero
+                ldd fpa1+fpa.sig+2
+                lbeq DIV0ERROR                  ; brif LSW is zero - division by zero
+int32_div1a     bsr util_div32                  ; do the actual division
                 lda ,s+                         ; get desired sign
                 bmi int32_div2                  ; brif want negative - we can't overflow in that case
-                ldb fpaextra                   ; get high byte of result
+                ldb fpaextra                    ; get high byte of result
                 lbmi OVERROR2                   ; brif we ended up with 0x80000000 positive
                 bra int32_div3                  ; go return result
 int32_div2      ldd zero                        ; negate result to correct sign