From 923fa8fc932638f2d8242433f86405e92cc426cd Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Fri, 9 Nov 2018 15:56:16 +0100 Subject: [PATCH] Saved 2 bytes and fixed error in case of negative result. --- libsrc/common/divt.s | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libsrc/common/divt.s b/libsrc/common/divt.s index f1291c86f..914eb569d 100644 --- a/libsrc/common/divt.s +++ b/libsrc/common/divt.s @@ -18,12 +18,15 @@ .importzp sreg, ptr1, tmp1 _div: jsr tosdivax ; Division-operator does most of the work - lda sreg ; Unsigned remainder is in sreg - ldx sreg+1 - ldy ptr1 ; transfer quotient to sreg - sty sreg - ldy ptr1+1 - sty sreg+1 + + ldy sreg ; low byte remainder from sreg + sta sreg ; store low byte quotient to sreg + + lda sreg+1 ; high byte remainder from sreg + stx sreg+1 ; store high byte quotient to sreg + + tax ; high byte remainder to x + tya ; low byte remainder to a ; Adjust the sign of the remainder. ; It must be the same as the sign of the dividend. @@ -33,4 +36,3 @@ _div: jsr tosdivax ; Division-operator does most of the work jmp negax ; Result is negative, adjust the sign Pos: rts -