Implemented RFE #1702376
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 5 Jan 2009 10:20:47 +0000 (10:20 +0000)
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 5 Jan 2009 10:20:47 +0000 (10:20 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5333 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/lib/z80/Makefile.in
device/lib/z80/div.s
device/lib/z80/divsigned.s [new file with mode: 0644]
device/lib/z80/mod.s [new file with mode: 0644]
device/lib/z80/mul.s
device/lib/z80/mulchar.s [new file with mode: 0644]

index 69f415a245fb3e164cf0a2acaeba39c8a85cea50..f42d5d890d4b02fd0e075ee99d0d6e2055f0dc74 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-01-05 Philipp Klaus Krause <pkk AT spth.de>
+
+       * /device/lib/z80/mod.s,
+         device/lib/z80/div.s,
+         device/lib/z80/mulchar.s,
+         device/lib/z80/mul.s,
+         device/lib/z80/divsigned.s,
+         device/lib/z80/Makefile.in:
+         Implemented RFE #1702376.
+
 2009-01-05 Borut Razem <borut.razem AT siol.net>
 
        * as/link/lksdcclib.c:
index 1f12889f7659f1fef35f13516f7652a2512d6f3c..0be6444d33c2120bf30dac5b1eeac4ada4afdb23 100644 (file)
@@ -8,7 +8,7 @@ TOPDIR = ../../..
 SCC = $(TOPDIR)/bin/sdcc -mz80
 SAS = $(TOPDIR)/bin/as-z80
 
-OBJ = div.o mul.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o memmove.o strlen.o
+OBJ = div.o divsigned.o mod.o mul.o mulchar.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o memmove.o strlen.o
 
 LIB = z80.lib
 CC = $(SCC)
index c34176b823b17a5e7a1dec48aa47efbdabb479d2..e64aa07b9fe4e9d70ce36011fe97a184f9a190df 100644 (file)
@@ -1,93 +1,6 @@
         ;; Originally from GBDK by Pascal Felber.
-        .area   _CODE
-
-__divschar_rrx_s::
-        ld      hl,#2+1
-        add     hl,sp
-
-        ld      e,(hl)
-        dec     hl
-        ld      l,(hl)
-
-        ;; Fall through
-__divschar_rrx_hds::
-        ld      c,l
-
-        call    .div8
-
-        ld      l,c
-        ld      h,b
-
-        ret
-
-__modschar_rrx_s::
-        ld      hl,#2+1
-        add     hl,sp
-
-        ld      e,(hl)
-        dec     hl
-        ld      l,(hl)
-
-        ;; Fall through
-__modschar_rrx_hds::
-        ld      c,l
-
-        call    .div8
-
-        ld      l,e
-        ld      h,d
-
-        ret
-
-__divsint_rrx_s::
-        ld      hl,#2+3
-        add     hl,sp
-
-        ld      d,(hl)
-        dec     hl
-        ld      e,(hl)
-        dec     hl
-        ld      a,(hl)
-        dec     hl
-        ld      l,(hl)
-        ld      h,a
-
-        ;; Fall through
-__divsint_rrx_hds::
-        ld      b,h
-        ld      c,l
-
-        call    .div16
-
-        ld      l,c
-        ld      h,b
-
-        ret
-
-__modsint_rrx_s::
-        ld      hl,#2+3
-        add     hl,sp
-
-        ld      d,(hl)
-        dec     hl
-        ld      e,(hl)
-        dec     hl
-        ld      a,(hl)
-        dec     hl
-        ld      l,(hl)
-        ld      h,a
 
-        ;; Fall through
-__modsint_rrx_hds::
-        ld      b,h
-        ld      c,l
-
-        call    .div16
-
-        ld      l,e
-        ld      h,d
-
-        ret
+        .area   _CODE
 
         ;; Unsigned
 __divuchar_rrx_s::
@@ -101,31 +14,13 @@ __divuchar_rrx_s::
         ;; Fall through
 __divuchar_rrx_hds::
         ld      c,l
-        call    .divu8
+        call    __divu8
 
         ld      l,c
         ld      h,b
 
         ret
 
-__moduchar_rrx_s::
-        ld      hl,#2+1
-        add     hl,sp
-
-        ld      e,(hl)
-        dec     hl
-        ld      l,(hl)
-
-        ;; Fall through
-__moduchar_rrx_hds::
-        ld      c,l
-        call    .divu8
-
-        ld      l,e
-        ld      h,d
-
-        ret
-
 __divuint_rrx_s::
         ld      hl,#2+3
         add     hl,sp
@@ -143,38 +38,13 @@ __divuint_rrx_s::
 __divuint_rrx_hds::
         ld      b,h
         ld      c,l
-        call    .divu16
+        call    __divu16
 
         ld      l,c
         ld      h,b
 
         ret
 
-__moduint_rrx_s::
-        ld      hl,#2+3
-        add     hl,sp
-
-        ld      d,(hl)
-        dec     hl
-        ld      e,(hl)
-        dec     hl
-        ld      a,(hl)
-        dec     hl
-        ld      l,(hl)
-        ld      h,a
-        ;; Fall through
-
-__moduint_rrx_hds::
-        ld      b,h
-        ld      c,l
-
-        call    .divu16
-
-        ld      l,e
-        ld      h,d
-
-        ret
-
 __divsuchar_rrx_s::
         ld      hl,#2+1
         add     hl,sp
@@ -221,35 +91,14 @@ __divuschar_rrx_s::
         sbc     a
         ld      b,a
 
-        call    .div16
+        call    __div16
 
         ld      l,c
         ld      h,b
 
         ret
 
-__moduschar_rrx_s::
-        ld      hl,#2+1
-        add     hl,sp
-
-        ld      e,(hl)
-        ld      d, #0
-        dec     hl
-        ld      c,(hl)
-
-        ld      a,c             ; Sign extend
-        rlca
-        sbc     a
-        ld      b,a
-
-        call    .div16
-
-        ld      l,e
-        ld      h,d
-
-        ret
-
-.div8::
+__div8::
 .mod8::
         ld      a,c             ; Sign extend
         rlca
@@ -261,7 +110,7 @@ signexte:
         sbc     a
         ld      d,a
 
-        ; Fall through to .div16
+        ; Fall through to __div16
 
         ;; 16-bit division
         ;;
@@ -276,7 +125,7 @@ signexte:
         ;;   If divisor is 0, carry=1 and both quotient and remainder are 0
         ;;
         ;; Register used: AF,BC,DE,HL
-.div16::
+__div16::
 .mod16::
         ;; Determine sign of quotient by xor-ing high bytes of dividend
         ;;  and divisor. Quotient is positive if signs are the same, negative
@@ -308,7 +157,7 @@ signexte:
         ld      b,a
         ;; Divide absolute values
 .dodiv:
-        call    .divu16
+        call    __divu16
         jr      C,.exit         ; Exit if divide by zero
         ;; Negate quotient if it is negative
         pop     af              ; recover sign of quotient
@@ -337,13 +186,13 @@ signexte:
         pop     af
         ret
 
-.divu8::
+__divu8::
 .modu8::
         ld      b,#0x00
         ld      d,b
         ; Fall through to divu16
 
-.divu16::
+__divu16::
 .modu16::
         ;; Check for division by zero
         ld      a,e
@@ -408,3 +257,4 @@ signexte:
 ;       ld      b,h             ; B = high byte of quotient
         or      a               ; Clear carry, valid result
         ret
+
diff --git a/device/lib/z80/divsigned.s b/device/lib/z80/divsigned.s
new file mode 100644 (file)
index 0000000..3614047
--- /dev/null
@@ -0,0 +1,90 @@
+        .area   _CODE
+
+__divschar_rrx_s::
+        ld      hl,#2+1
+        add     hl,sp
+
+        ld      e,(hl)
+        dec     hl
+        ld      l,(hl)
+
+        ;; Fall through
+__divschar_rrx_hds::
+        ld      c,l
+
+        call    __div8
+
+        ld      l,c
+        ld      h,b
+
+        ret
+
+__modschar_rrx_s::
+        ld      hl,#2+1
+        add     hl,sp
+
+        ld      e,(hl)
+        dec     hl
+        ld      l,(hl)
+
+        ;; Fall through
+__modschar_rrx_hds::
+        ld      c,l
+
+        call    __div8
+
+        ld      l,e
+        ld      h,d
+
+        ret
+
+__divsint_rrx_s::
+        ld      hl,#2+3
+        add     hl,sp
+
+        ld      d,(hl)
+        dec     hl
+        ld      e,(hl)
+        dec     hl
+        ld      a,(hl)
+        dec     hl
+        ld      l,(hl)
+        ld      h,a
+
+        ;; Fall through
+__divsint_rrx_hds::
+        ld      b,h
+        ld      c,l
+
+        call    __div16
+
+        ld      l,c
+        ld      h,b
+
+        ret
+
+__modsint_rrx_s::
+        ld      hl,#2+3
+        add     hl,sp
+
+        ld      d,(hl)
+        dec     hl
+        ld      e,(hl)
+        dec     hl
+        ld      a,(hl)
+        dec     hl
+        ld      l,(hl)
+        ld      h,a
+
+        ;; Fall through
+__modsint_rrx_hds::
+        ld      b,h
+        ld      c,l
+
+        call    __div16
+
+        ld      l,e
+        ld      h,d
+
+        ret
+
diff --git a/device/lib/z80/mod.s b/device/lib/z80/mod.s
new file mode 100644 (file)
index 0000000..763cf6c
--- /dev/null
@@ -0,0 +1,66 @@
+        .area   _CODE
+
+__moduchar_rrx_s::
+        ld      hl,#2+1
+        add     hl,sp
+
+        ld      e,(hl)
+        dec     hl
+        ld      l,(hl)
+
+        ;; Fall through
+__moduchar_rrx_hds::
+        ld      c,l
+        call    __divu8
+
+        ld      l,e
+        ld      h,d
+
+        ret
+
+__moduint_rrx_s::
+        ld      hl,#2+3
+        add     hl,sp
+
+        ld      d,(hl)
+        dec     hl
+        ld      e,(hl)
+        dec     hl
+        ld      a,(hl)
+        dec     hl
+        ld      l,(hl)
+        ld      h,a
+        ;; Fall through
+
+__moduint_rrx_hds::
+        ld      b,h
+        ld      c,l
+
+        call    __divu16
+
+        ld      l,e
+        ld      h,d
+
+        ret
+
+__moduschar_rrx_s::
+        ld      hl,#2+1
+        add     hl,sp
+
+        ld      e,(hl)
+        ld      d, #0
+        dec     hl
+        ld      c,(hl)
+
+        ld      a,c             ; Sign extend
+        rlca
+        sbc     a
+        ld      b,a
+
+        call    __div16
+
+        ld      l,e
+        ld      h,d
+
+        ret
+
index 6dd917a1ec2c5961c24c9d838c5d27695915fa51..b54fd9d73962dbad55f1c08b3dc0d4c1abf0e575 100644 (file)
@@ -1,76 +1,5 @@
         .area   _CODE
 
-; This multiplication routine is similar to the one
-; from Rodnay Zaks, "Programming the Z80".
-
-; Now replaced by a builtin for code generation, but
-; still called from some asm files in this directory.
-__muluchar_rrx_s::
-        ld      hl, #2+1
-        add     hl, sp
-        ld      e, (hl)
-        dec     hl
-        ld      h, (hl)
-        ld      l, #0
-        ld      d, l
-        ld      b, #8
-muluchar_rrx_s_loop:
-        add     hl, hl
-        jr      nc, muluchar_rrx_s_noadd
-        add     hl, de
-muluchar_rrx_s_noadd:
-        djnz    muluchar_rrx_s_loop
-        ret
-
-; operands have different sign
-
-__mulsuchar_rrx_s::
-        ld      hl,#2+1
-        add     hl,sp
-
-        ld      e,(hl)
-        dec     hl
-        ld      c,(hl)
-        ld      b, #0
-        jr      signexte
-
-__muluschar_rrx_s::
-        ld      hl,#2+1
-        add     hl,sp
-
-        ld      c,(hl)
-        ld      b, #0
-        dec     hl
-        ld      e,(hl)
-        jr      signexte
-
-;; Originally from GBDK by Pascal Felber.
-
-__mulschar_rrx_s::
-        ld      hl,#2+1
-        add     hl,sp
-
-        ld      e,(hl)
-        dec     hl
-        ld      l,(hl)
-
-        ;; Fall through
-__mulschar_rrx_hds::
-        ;; Need to sign extend before going in.
-        ld      c,l
-
-        ld      a,l
-        rla
-        sbc     a,a
-        ld      b,a
-signexte:
-        ld      a,e
-        rla
-        sbc     a,a
-        ld      d,a
-
-        jr      .mul16
-
 __mulint_rrx_s::
         ld      hl,#2
         add     hl,sp
@@ -103,7 +32,7 @@ __mulint_rrx_hds::
        ;;   DE = less significant word of product
        ;;
        ;; Register used: AF,BC,DE,HL
-.mul16:
+__mul16::
         ld      hl,#0
         ld      a,b
         ; ld c,c
@@ -127,3 +56,4 @@ __mulint_rrx_hds::
 2$:
         djnz    1$
         ret
+
diff --git a/device/lib/z80/mulchar.s b/device/lib/z80/mulchar.s
new file mode 100644 (file)
index 0000000..7217dd8
--- /dev/null
@@ -0,0 +1,73 @@
+        .area   _CODE
+
+; This multiplication routine is similar to the one
+; from Rodnay Zaks, "Programming the Z80".
+
+; Now replaced by a builtin for code generation, but
+; still called from some asm files in this directory.
+__muluchar_rrx_s::
+        ld      hl, #2+1
+        add     hl, sp
+        ld      e, (hl)
+        dec     hl
+        ld      h, (hl)
+        ld      l, #0
+        ld      d, l
+        ld      b, #8
+muluchar_rrx_s_loop:
+        add     hl, hl
+        jr      nc, muluchar_rrx_s_noadd
+        add     hl, de
+muluchar_rrx_s_noadd:
+        djnz    muluchar_rrx_s_loop
+        ret
+
+; operands have different sign
+
+__mulsuchar_rrx_s::
+        ld      hl,#2+1
+        add     hl,sp
+
+        ld      e,(hl)
+        dec     hl
+        ld      c,(hl)
+        ld      b, #0
+        jr      signexte
+
+__muluschar_rrx_s::
+        ld      hl,#2+1
+        add     hl,sp
+
+        ld      c,(hl)
+        ld      b, #0
+        dec     hl
+        ld      e,(hl)
+        jr      signexte
+
+;; Originally from GBDK by Pascal Felber.
+
+__mulschar_rrx_s::
+        ld      hl,#2+1
+        add     hl,sp
+
+        ld      e,(hl)
+        dec     hl
+        ld      l,(hl)
+
+        ;; Fall through
+__mulschar_rrx_hds::
+        ;; Need to sign extend before going in.
+        ld      c,l
+
+        ld      a,l
+        rla
+        sbc     a,a
+        ld      b,a
+signexte:
+        ld      a,e
+        rla
+        sbc     a,a
+        ld      d,a
+
+        jp      __mul16
+