]> git.sur5r.net Git - cc65/commitdiff
Added 16*16=32 multiplication routine.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 3 Nov 2009 13:40:03 +0000 (13:40 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 3 Nov 2009 13:40:03 +0000 (13:40 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4434 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/runtime/Makefile
libsrc/runtime/mul16x16r32.s [new file with mode: 0644]
libsrc/runtime/mul8x8r16.s

index 34052761cc77fcf3749de210b10d351b82c4108b..b92863cab8c5073e7f75fcac66729bae2d61bee8 100644 (file)
@@ -152,6 +152,7 @@ OBJS =      add.o           \
                makebool.o      \
                mod.o           \
                mul.o           \
+        mul16x16r32.o   \
         mul8.o          \
         mul8x8r16.o     \
        mulax3.o        \
diff --git a/libsrc/runtime/mul16x16r32.s b/libsrc/runtime/mul16x16r32.s
new file mode 100644 (file)
index 0000000..968903d
--- /dev/null
@@ -0,0 +1,49 @@
+;
+; Ullrich von Bassewitz, 2010-11-03
+;
+; CC65 runtime: 16x16 => 32 multiplication
+;
+
+        .export         umul16x16r32
+               .export         mul16x16r32 := umul16x16r32
+       .importzp       ptr1, ptr2, ptr3, ptr4, sreg
+
+
+;---------------------------------------------------------------------------
+; 16x16 => 32 multiplication routine.
+;
+;   lhs         rhs           result          result also in
+; -------------------------------------------------------------
+;   ptr1        ptr3           ax:sreg          ptr1:sreg
+;
+
+umul16x16r32:
+               lda     #0
+               ldx     ptr3+1          ; Get high byte into register for speed
+               sta     sreg+1
+               ldy     #16             ; Number of bits
+
+        lsr     ptr1+1
+        ror     ptr1            ; Get first bit into carry
+@L0:    bcc     @L1
+
+       clc
+       adc     ptr3
+       pha
+               txa                     ; hi byte of left op
+       adc     sreg+1
+       sta     sreg+1
+       pla
+
+@L1:    ror     sreg+1
+       ror     a
+       ror     ptr1+1
+       ror     ptr1
+        dey
+        bne     @L0
+
+        sta     sreg            ; Save byte 3
+       lda     ptr1            ; Load the result
+       ldx     ptr1+1
+       rts                     ; Done
+
index b1e679f69027ead1b0b24269614a37e2b5613a7a..a09618124fc339125532dea3082ee29b996ca648 100644 (file)
@@ -4,7 +4,8 @@
 ; CC65 runtime: 8x8 => 16 multiplication
 ;
 
-               .export         mul8x8r16, umul8x8r16
+               .export         umul8x8r16
+        .export         mul8x8r16 := umul8x8r16
        .importzp       ptr1, ptr3
 
 
 ;
 ;   lhs         rhs           result          result also in
 ; -------------------------------------------------------------
-;   ptr1-lo     ptr3-lo         a/x             ptr1
+;   ptr1-lo     ptr3-lo         a             ptr1
 ;
 
-mul8x8r16:
 umul8x8r16:
        lda     #0              ; Clear byte 1
                ldy     #8              ; Number of bits
@@ -28,7 +28,7 @@ umul8x8r16:
         ror     ptr1
         dey
         bne     @L0
-        tax         
+        tax
         stx     ptr1+1          ; Result in a/x and ptr1
        lda     ptr1            ; Load the result
        rts                     ; Done