diff --git a/libsrc/runtime/imul8x8r16.s b/libsrc/runtime/imul8x8r16.s index 72e6d03a2..fe939f668 100644 --- a/libsrc/runtime/imul8x8r16.s +++ b/libsrc/runtime/imul8x8r16.s @@ -32,24 +32,7 @@ imul8x8r16m: ldy #<$0000 ; Clear .XY accumulator ldx #>$0000 lda ptr1 - bmi NegMult - bpl @L2 ; Branch always - -@L0: tya ; Add current multiplicand - add ptr3 - tay - txa - adc ptr3+1 - tax - -@L1: asl ptr3 - rol ptr3+1 -@L2: lsr ptr1 ; Get next bit of Right-Hand Side into carry - bcs @L0 - bnz @L1 ; Loop if more one-bits in multiplier - - tya ; Put result into cc65's accumulator - rts + bpl PosStart ; The multiplier is negative. ; Therefore, make it positive; and, subtract when multiplying. @@ -57,9 +40,10 @@ NegMult: eor #%11111111 sta ptr1 inc ptr1 - bnz @L2 ; Branch always + bnz NegStart ; Branch always -@L0: tya ; Subtract current multiplicand +NegAdd: + tya ; Subtract current multiplicand ; sec sbc ptr3 tay @@ -67,11 +51,34 @@ NegMult: sbc ptr3+1 tax -@L1: asl ptr3 +NegShift: + asl ptr3 rol ptr3+1 -@L2: lsr ptr1 ; Get next bit of Right-Hand Side into carry - bcs @L0 - bnz @L1 ; Loop if more one-bits in multiplier +NegStart: + lsr ptr1 ; Get next bit of Right-Hand Side into carry + bcs NegAdd + bnz NegShift ; Loop if more one-bits in multiplier + + tya ; Put result into cc65's accumulator + rts + +; The multiplier is positive. + +PosAdd: + tya ; Add current multiplicand + add ptr3 + tay + txa + adc ptr3+1 + tax + +PosShift: + asl ptr3 + rol ptr3+1 +PosStart: + lsr ptr1 ; Get next bit of Right-Hand Side into carry + bcs PosAdd + bnz PosShift ; Loop if more one-bits in multiplier tya ; Put result into cc65's accumulator rts