From 2109a06030f5d8dcb7412a67cf61315e6f69a427 Mon Sep 17 00:00:00 2001 From: spth Date: Mon, 5 Jan 2009 10:20:47 +0000 Subject: [PATCH] Implemented RFE #1702376 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5333 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 10 +++ device/lib/z80/Makefile.in | 2 +- device/lib/z80/div.s | 172 +++---------------------------------- device/lib/z80/divsigned.s | 90 +++++++++++++++++++ device/lib/z80/mod.s | 66 ++++++++++++++ device/lib/z80/mul.s | 74 +--------------- device/lib/z80/mulchar.s | 73 ++++++++++++++++ 7 files changed, 253 insertions(+), 234 deletions(-) create mode 100644 device/lib/z80/divsigned.s create mode 100644 device/lib/z80/mod.s create mode 100644 device/lib/z80/mulchar.s diff --git a/ChangeLog b/ChangeLog index 69f415a2..f42d5d89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-01-05 Philipp Klaus Krause + + * /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 * as/link/lksdcclib.c: diff --git a/device/lib/z80/Makefile.in b/device/lib/z80/Makefile.in index 1f12889f..0be6444d 100644 --- a/device/lib/z80/Makefile.in +++ b/device/lib/z80/Makefile.in @@ -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) diff --git a/device/lib/z80/div.s b/device/lib/z80/div.s index c34176b8..e64aa07b 100644 --- a/device/lib/z80/div.s +++ b/device/lib/z80/div.s @@ -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 index 00000000..3614047f --- /dev/null +++ b/device/lib/z80/divsigned.s @@ -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 index 00000000..763cf6ce --- /dev/null +++ b/device/lib/z80/mod.s @@ -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 + diff --git a/device/lib/z80/mul.s b/device/lib/z80/mul.s index 6dd917a1..b54fd9d7 100644 --- a/device/lib/z80/mul.s +++ b/device/lib/z80/mul.s @@ -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 index 00000000..7217dd88 --- /dev/null +++ b/device/lib/z80/mulchar.s @@ -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 + -- 2.39.5