# HG changeset patch # User William Astle # Date 1703717879 25200 # Node ID e72cda5e5ee267f77bbc3cc28dd0eb305e511464 # Parent 03eb6d6b49b4569e68a3b574ea3fd91f636c5460 Fix logic errors in floating point division diff -r 03eb6d6b49b4 -r e72cda5e5ee2 src/fps.s --- a/src/fps.s Wed Dec 27 00:07:05 2023 -0700 +++ b/src/fps.s Wed Dec 27 15:57:59 2023 -0700 @@ -693,35 +693,29 @@ lslb lslb lslb - sta fpaextra+8 ; save it + stb fpaextra+8 ; save it bsr fps_div5 ; do next digit addb fpaextra+8 ; combine the two quotient digits fps_div4 rts -fps_div5 ldb fpaextra+6 ; do we even need to do the division? - beq fps_div4 ; brif not - return 0 - clrb ; initialize quotient digit +fps_div5 clrb ; initialize digit value fps_div6 lda fpaextra+7 ; did we have a carry last time? bne fps_div7 ; brif so - we know it "goes" lda fpa1+fpa.sig ; is the divisor less than the dividend residue? cmpa fpa1+fpa.sig+5 - bhi fps_div8 ; brif high byte is larger than residue + bne fps_div6a ; brif high byte is larger than residue lda fpa1+fpa.sig+1 ; and keep going for all 5 bytes cmpa fpa1+fpa.sig+6 - bhi fps_div8 + bne fps_div6a lda fpa1+fpa.sig+2 cmpa fpa1+fpa.sig+7 - bhi fps_div8 + bne fps_div6a lda fpa1+fpa.sig+3 cmpa fpa1+fpa.sig+8 - bhi fps_div8 + bhi fps_div6a lda fpa1+fpa.sig+4 cmpa fpa1+fpa.sig+9 - bhi fps_div8 ; brif divisor is greater than the residue - bne fps_div7 ; brif it didn't go exactly - incb ; bump quotient for this "go" - clr fpaextra+6 ; indicate no more digits needed - rts -fps_div7 coma ; set carry to complete 10's complement of divisor +fps_div6a bhi fps_div8 ; brif divisor is greater than the residue +fps_div7 coma ; set carry to complete 10's complement of divisor lda fpa1+fpa.sig+9 ; do the "subtraction" adca fpaextra+4 daa @@ -744,17 +738,11 @@ sta fpa1+fpa.sig+5 lda fpaextra+7 ; and handle the carry byte adca #0x99 + daa sta fpaextra+7 incb ; bump digit count bra fps_div6 ; go see if we need another subtraction -fps_div8 tstb ; nonzero digit? - beq fps_div9 ; brif not - lda #1 ; set nonzero flag - sta fpaextra+5 -fps_div9 lda fpaextra+6 ; adjust digit count - suba fpaextra+5 - sta fpaextra+6 - lsl fpa1+fpa.sig+9 ; shift residue one decimal digit +fps_div8 lsl fpa1+fpa.sig+9 ; shift residue one decimal digit rol fpa1+fpa.sig+8 rol fpa1+fpa.sig+7 rol fpa1+fpa.sig+6