+2009-04-19 Philipp Klaus Krause <pkk AT spth.de>
+ * device/lib/z80/shift.s,
+ device/lib/z80/memmove.s,
+ device/lib/z80/mul.s,
+ device/lib/z80/mulchar.s,
+ device/lib/z80/div.s,
+ device/lib/z80/mod.s:
+ Applied patch #2762516 from Marco Bodrato containing minor
+ improvementsof many Z80 asm routines.
+
2009-04-19 Philipp Klaus Krause <pkk AT spth.de>
* support/regression/tests/strtok.c,
__divuschar_rrx_s::
ld hl,#2+1
+ ld d, h
add hl,sp
ld e,(hl)
- ld d, #0
dec hl
ld l,(hl)
ld e,c ; DE = quotient, HL = remainder
ex de,hl ; HL = quotient, DE = remainder
ret
-
; Copyright (C) 2008-2009
-; Philipp Klaus Krause
+; Philipp Klaus Krause, Marco Bodrato
; This file is part of the sdcc Library. This library is free
; software; you can redistribute it and/or modify it under the
; The Z80 has the ldir and lddr instructions, which are perfect for implementing memmove().
_memmove:
- push ix
- ld ix, #0
- add ix, sp
- ld c, 8(ix)
- ld b, 9(ix)
+ pop af
+ pop hl
+ pop de
+ pop bc
+ push bc
+ push de
+ push hl
+ push af
ld a, c
or a, b
- jr Z, memmove_end
- ld e, 4(ix)
- ld d, 5(ix)
- ld l, 6(ix)
- ld h, 7(ix)
- ld a, l
- sbc hl, de ; or above cleared carry.
- ld l, a
- ld h, 7(ix)
- jr NC, memmove_up
+ ret Z
+ push hl
+ sbc hl, de ; or above cleared carry.
+ add hl, de ; same carry as the line before
+ jr C, memmove_up
memmove_down:
+ dec bc
add hl, bc
- dec hl
- ld a, e
- add a, c
- ld e, a
- ld a, d
- adc a, b
- ld d, a
- dec de
+ ex de, hl
+ add hl, bc
+ inc bc
lddr
- jr memmove_end
+ pop hl
+ ret
memmove_up:
+ ex de, hl
ldir
-memmove_end:
- ld l, 4(ix)
- ld h, 5(ix)
- pop ix
+ pop hl
ret
ret
__moduint_rrx_s::
- ld hl,#2+3
- add hl,sp
+ pop af
+ pop hl
+ pop de
+ push de
+ push hl
+ push af
- 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::
call __divu16
__moduschar_rrx_s::
ld hl,#2+1
+ ld d, h
add hl,sp
ld e,(hl)
- ld d, #0
dec hl
ld l,(hl)
.area _CODE
__mulint_rrx_s::
- ld hl,#2
- add hl,sp
-
- ld e,(hl)
- inc hl
- ld d,(hl)
- inc hl
- ld a,(hl)
- inc hl
- ld h,(hl)
- ld l,a
+ pop af
+ pop hl
+ pop de
+ push de
+ push hl
+ push af
;; Fall through
; still called from some asm files in this directory.
__muluchar_rrx_s::
ld hl, #2+1
+ ld d, h
add hl, sp
ld e, (hl)
dec hl
ld h, (hl)
- ld l, #0
- ld d, l
+ ld l, d
ld b, #8
muluchar_rrx_s_loop:
add hl, hl
__mulsuchar_rrx_s::
ld hl,#2+1
+ ld b, h
add hl,sp
ld e,(hl)
dec hl
ld c,(hl)
- ld b, #0
jr signexte
__muluschar_rrx_s::
- ld hl,#2+1
+ ld hl,#2
+ ld b, h
add hl,sp
- ld c,(hl)
- ld b, #0
- dec hl
ld e,(hl)
+ inc hl
+ ld c,(hl)
jr signexte
;; Originally from GBDK by Pascal Felber.
ld hl,#2+4
add hl,sp
- ld c,(hl)
- dec hl
- ld d,(hl)
- dec hl
- ld e,(hl)
- dec hl
ld a,(hl)
- dec hl
- ld l,(hl)
- ld h,a
-
- ld a,c
-1$:
or a,a
+ pop bc
+ pop hl
+ pop de
+ push de
+ push hl
+ push bc
ret Z
-
- rr d
- rr e
- rr h
+ ld b,a
+ ld a,e
+1$:
+ srl d
+ rra
+ rr h
rr l
- dec a
- jp 1$
+ djnz 1$
+ ld e,a
+ ret
__rrslong_rrx_s::
ld hl,#2+4
add hl,sp
- ld c,(hl)
- dec hl
- ld d,(hl)
- dec hl
- ld e,(hl)
- dec hl
ld a,(hl)
- dec hl
- ld l,(hl)
- ld h,a
-
- ld a,c
-1$:
or a,a
+ pop bc
+ pop hl
+ pop de
+ push de
+ push hl
+ push bc
ret Z
-
+ ld b,a
+ ld a,e
+2$:
sra d
- rr e
- rr h
+ rra
+ rr h
rr l
- dec a
- jp 1$
+ djnz 2$
+ ld e,a
+ ret
__rlslong_rrx_s::
__rlulong_rrx_s::
ld hl,#2+4
add hl,sp
- ld c,(hl)
- dec hl
- ld d,(hl)
- dec hl
- ld e,(hl)
- dec hl
ld a,(hl)
- dec hl
- ld l,(hl)
- ld h,a
-
- ld a,c
-1$:
or a,a
+ pop bc
+ pop hl
+ pop de
+ push de
+ push hl
+ push bc
ret Z
+ ld b,a
+ ld a,e
+3$:
+ add hl,hl
+ rla
+ rl d
- rl l
- rl h
- rl e
- rl d
-
- dec a
- jp 1$
+ djnz 3$
+ ld e,a
+ ret