]> git.sur5r.net Git - cc65/commitdiff
Added division routine. Removed C callable entry points from mul routines,
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 4 Nov 2009 18:23:40 +0000 (18:23 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 4 Nov 2009 18:23:40 +0000 (18:23 +0000)
they're now in common.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4441 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/runtime/Makefile
libsrc/runtime/imul16x16r32.s
libsrc/runtime/udiv32by16r16.s [new file with mode: 0644]
libsrc/runtime/umul16x16r32.s

index adb35a8f9eb8fe56b7eeac572f762cec629df03e..c8a76beabf5b424462b9d52f6893d096fbfff95b 100644 (file)
@@ -218,6 +218,7 @@ OBJS =      add.o           \
                ugt.o           \
                ule.o           \
                ult.o           \
+        udiv32by16r16.o \
                umod.o          \
         umul16x16r32.o  \
                xor.o           \
index d105b72a3b8b5a2722bf86eb92f9645a5671d5df..b9101f339f62e9ebc59441c2d28cc4e2da3e85b5 100644 (file)
@@ -4,8 +4,8 @@
 ; CC65 runtime: 16x16 => 32 signed multiplication
 ;
 
-        .export         imul16x16r32, _cc65_imul16x16r32
-        .import         popax, negax, umul16x16r32m, negeax
+        .export         imul16x16r32
+        .import         negax, umul16x16r32m, negeax
        .importzp       ptr1, ptr3, tmp1
 
 
 ; There is probably a faster way to do this.
 ;
 
-
-_cc65_imul16x16r32:
-        sta     ptr1
-        stx     ptr1+1
-        jsr     popax
-
 imul16x16r32:
         stx     tmp1
         cpx     #0
diff --git a/libsrc/runtime/udiv32by16r16.s b/libsrc/runtime/udiv32by16r16.s
new file mode 100644 (file)
index 0000000..ac048bd
--- /dev/null
@@ -0,0 +1,55 @@
+;
+; Ullrich von Bassewitz, 2009-11-04
+;
+; CC65 runtime: 32by16 => 16 unsigned division
+;
+
+               .export         udiv32by16r16, udiv32by16r16m
+       .importzp       ptr1, ptr2, ptr3, sreg
+
+
+;---------------------------------------------------------------------------
+; 32by16 division. Divide ptr1:ptr2 by ptr3. Result is in ptr1, remainder
+; in sreg.
+;
+;   lhs         rhs           result      result also in    remainder
+; -----------------------------------------------------------------------
+;   ptr1:ptr2   ptr3          ax          ptr1              sreg
+;
+
+
+udiv32by16r16:
+        sta     ptr3
+        stx     ptr3+1
+udiv32by16r16m:
+        lda            #0
+       sta     sreg+1
+       ldy     #32
+
+L0:            asl     ptr1
+        rol     ptr1+1
+        rol     ptr2
+        rol     ptr2+1
+        rol     a
+        rol     sreg+1
+
+       pha
+       cmp     ptr3
+       lda     sreg+1
+       sbc     ptr3+1
+       bcc     L1
+
+       sta     sreg+1
+       pla
+       sbc     ptr3
+       pha
+       inc     ptr1
+
+L1:    pla
+       dey
+       bne     L0
+       sta     sreg
+        lda     ptr1
+        ldx     ptr1+1
+       rts
+
index d86162c7a6f67449fc849d97814863080c083235..75d6157feab27a8b1791a4d7623320f966dcb5a4 100644 (file)
@@ -4,8 +4,7 @@
 ; CC65 runtime: 16x16 => 32 unsigned multiplication
 ;
 
-        .export         _cc65_umul16x16r32, umul16x16r32, umul16x16r32m
-        .import         popax
+        .export         umul16x16r32, umul16x16r32m
        .importzp       ptr1, ptr3, sreg
 
 
 ;   ptr1        ax            ax:sreg          ptr1:sreg
 ;
 
-_cc65_umul16x16r32:
-        sta     ptr1
-        stx     ptr1+1
-        jsr     popax
-
 umul16x16r32:
         sta     ptr3
         stx     ptr3+1