From 0c1703f8fd84e8f75b0775e4225766582324eb32 Mon Sep 17 00:00:00 2001 From: uz Date: Tue, 3 Nov 2009 13:40:03 +0000 Subject: [PATCH] Added 16*16=32 multiplication routine. git-svn-id: svn://svn.cc65.org/cc65/trunk@4434 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/runtime/Makefile | 1 + libsrc/runtime/mul16x16r32.s | 49 ++++++++++++++++++++++++++++++++++++ libsrc/runtime/mul8x8r16.s | 8 +++--- 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 libsrc/runtime/mul16x16r32.s diff --git a/libsrc/runtime/Makefile b/libsrc/runtime/Makefile index 34052761c..b92863cab 100644 --- a/libsrc/runtime/Makefile +++ b/libsrc/runtime/Makefile @@ -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 index 000000000..968903de5 --- /dev/null +++ b/libsrc/runtime/mul16x16r32.s @@ -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 + diff --git a/libsrc/runtime/mul8x8r16.s b/libsrc/runtime/mul8x8r16.s index b1e679f69..a09618124 100644 --- a/libsrc/runtime/mul8x8r16.s +++ b/libsrc/runtime/mul8x8r16.s @@ -4,7 +4,8 @@ ; CC65 runtime: 8x8 => 16 multiplication ; - .export mul8x8r16, umul8x8r16 + .export umul8x8r16 + .export mul8x8r16 := umul8x8r16 .importzp ptr1, ptr3 @@ -13,10 +14,9 @@ ; ; lhs rhs result result also in ; ------------------------------------------------------------- -; ptr1-lo ptr3-lo a/x ptr1 +; ptr1-lo ptr3-lo ax 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 -- 2.39.5