+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:
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)
;; 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::
;; 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
__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
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
sbc a
ld d,a
- ; Fall through to .div16
+ ; Fall through to __div16
;; 16-bit division
;;
;; 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
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
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
; ld b,h ; B = high byte of quotient
or a ; Clear carry, valid result
ret
+
--- /dev/null
+ .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
+
--- /dev/null
+ .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
+
.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
;; DE = less significant word of product
;;
;; Register used: AF,BC,DE,HL
-.mul16:
+__mul16::
ld hl,#0
ld a,b
; ld c,c
2$:
djnz 1$
ret
+
--- /dev/null
+ .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
+