z88dk forums

z80 Development Kit

You are not logged in.

  • Index
  •  » z88dk-commits
  •  » [Z88dk-commits] CVS: z88dk/libsrc/z80_crt0s/crt0_sdcc divmixed.asm,

#1 2010-09-19 14:45:28

Dominic Morris
Guest

[Z88dk-commits] CVS: z88dk/libsrc/z80_crt0s/crt0_sdcc divmixed.asm,

Update of /cvsroot/z88dk/z88dk/libsrc/z80_crt0s/crt0_sdcc
In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv22757

Added Files:
divmixed.asm divsigned.asm divunsigned.asm modmixed.asm
modsigned.asm modunsigned.asm mul.asm mulchar.asm shift.asm
Log Message:
Check sdcc crt0 code - this under GPL - and duplicates a lot of
the sccz80 code (but with different labels!)


--- NEW FILE: divmixed.asm ---
;--------------------------------------------------------------------------
;  divmixed.s
;
;  Copyright (C) 2010, Philipp Klaus Krause
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------
XLIB __divsuchar_rrx_s
LIB    __div16
LIB __div_signexte

__divsuchar_rrx_s:
ld      hl,#2+1
add     hl,sp

ld      e,(hl)
dec     hl
ld      l,(hl)
ld      h,#0

jp      __div_signexte

__divuschar_rrx_s:
ld      hl,#2+1
ld      d, h
add     hl,sp

ld      e,(hl)
dec     hl
ld      l,(hl)

ld      a,l             ; Sign extend
rlca
sbc     a
ld      h,a

jp      __div16



--- NEW FILE: divsigned.asm ---
;--------------------------------------------------------------------------
;  divsigned.s
;
;  Copyright (C) 2000-2010, Michael Hope, Philipp Klaus Krause
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

XLIB __divsint_rrx_s

LIB    __divu16
XDEF    __div16
XDEF __div8
XDEF __divsint_rrx_hds
XDEF __get_remainder

__divsint_rrx_s:
pop     af
pop     hl
pop     de
push    de
push    hl
push    af

jp      __div16

__divschar_rrx_s:
ld      hl, #2+1
add     hl, sp

ld      e, (hl)
dec     hl
ld      l, (hl)

;; Fall through
__divschar_rrx_hds:
__div8:
ld      a, l            ; Sign extend
rlca
sbc     a
ld      h, a
__div_signexte:
ld      a, e            ; Sign extend
rlca
sbc     a
ld      d, a
; Fall through to __div16

;; signed 16-bit division
;;
;; Entry conditions
;;   HL = dividend
;;   DE = divisor
;;
;; Exit conditions
;;   HL = quotient
;;   DE = remainder
;;
;; Register used: AF,B,DE,HL
__divsint_rrx_hds:
__div16:
;; Determine sign of quotient by xor-ing high bytes of dividend
;;  and divisor. Quotient is positive if signs are the same, negative
;;  if signs are different
;; Remainder has same sign as dividend
ld      a, h            ; Get high byte of dividend
xor     d               ; Xor with high byte of divisor
rla                     ; Sign of quotient goes into the carry
ld      a, h            ; Get high byte of dividend
push    af              ; Save sign of both quotient and reminder

; Take absolute value of dividend
rla
jr      NC, chkde      ; Jump if dividend is positive
sub     a, a            ; Substract dividend from 0
sub     a, l
ld      l, a
sbc     a, a            ; Propagate borrow (A=0xFF if borrow)
sub     a, h
ld      h, a

; Take absolute value of divisor
.chkde
bit     7, d
jr      Z, dodiv       ; Jump if divisor is positive
sub     a, a            ; Subtract divisor from 0
sub     a, e
ld      e, a
sbc     a, a            ; Propagate borrow (A=0xFF if borrow)
sub     a, d
ld      d, a

; Divide absolute values
.dodiv
call    __divu16

.fix_quotient
; Negate quotient if it is negative
pop     af              ; recover sign of quotient
ret    NC        ; Jump if quotient is positive
ld      b, a
sub     a, a            ; Subtract quotient from 0
sub     a, l
ld      l, a
sbc     a, a            ; Propagate borrow (A=0xFF if borrow)
sub     a, h
ld      h, a
ld      a, b
ret

__get_remainder:
; Negate remainder if it is negative and move it into hl
rla
ex    de, hl
ret     NC              ; Return if remainder is positive
sub     a, a            ; Subtract remainder from 0
sub     a, l
ld      l, a
sbc     a, a             ; Propagate remainder (A=0xFF if borrow)
sub     a, h
ld      h, a
ret


--- NEW FILE: divunsigned.asm ---
;--------------------------------------------------------------------------
;  divunsigned.s
;
;  Copyright (C) 2000-2010, Michael Hope, Philipp Klaus Krause, Marco Bodrato
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

;; Originally from GBDK by Pascal Felber.

XLIB __divuint_rrx_s
XDEF __divuchar_rrx_hds
XDEF __divu8
XDEF __divuint_rrx_hds
XDEF __divu16

__divuint_rrx_s:
pop     af
pop     hl
pop     de
push    de
push    hl
push    af

jr      __divu16

__divuchar_rrx_s:
ld      hl,#2+1
add     hl,sp

ld      e,(hl)
dec     hl
ld      l,(hl)

;; Fall through
__divuchar_rrx_hds:
__divu8:
ld      h,#0x00
ld      d,h
; Fall through to __divu16

;; unsigned 16-bit division
;;
;; Entry conditions
;;   HL = dividend
;;   DE = divisor
;;
;; Exit conditions
;;   HL = quotient
;;   DE = remainder
;;   If divisor is non-zero, carry=0
;;   If divisor is 0, carry=1 and both quotient and remainder are 0
;;
;; Register used: AF,B,DE,HL
__divuint_rrx_hds:
__divu16:
;; Check for division by zero
ld      a,e
or      d
;; Two algorithms: one assumes divisor <2^7, the second
;; assumes divisor >=2^7; choose the applicable one.
and     #0x80
jr      NZ,morethan7bits
or      d
jr      NZ,morethan7bits
;; Both algorithms "rotate" 24 bits (H,L,A) but roles change.

;; unsigned 16/7-bit division
.atmost7bits
ld      b,#16           ; bits in dividend and possible quotient
;; Carry cleared by AND/OR, this "0" bit will pass trough HL.[*]
adc     hl,hl
.dvloop7
;; HL holds both dividend and quotient. While we shift a bit from
;;  MSB of dividend, we shift next bit of quotient in from carry.
;; A holds remainder.
rla

;; If remainder is >= divisor, next bit of quotient is 1.  We try
;;  to compute the difference.
sub     a,e
jr      NC,nodrop7     ; Jump if remainder is >= dividend
add     a,e             ; Otherwise, restore remainder
;; The add above sets the carry, because sbc a,e did set it.
.nodrop7
ccf                     ; Complement borrow so 1 indicates a
;  successful substraction (this is the
;  next bit of quotient)
adc     hl,hl
djnz    dvloop7
;; Carry now contains the same value it contained before
;; entering .dvloop7[*]: "0" = valid result.
ld      e,a             ; DE = remainder, HL = quotient
ret

.morethan7bits
ld      b,#9            ; at most 9 bits in quotient.
ld      a,l             ; precompute the first 7 shifts, by
ld      l,h             ;  doing 8
ld      h,#0
rr      l               ;  undoing 1
.dvloop
;; Shift next bit of quotient into bit 0 of dividend
;; Shift next MSB of dividend into LSB of remainder
;; A holds both dividend and quotient. While we shift a bit from
;;  MSB of dividend, we shift next bit of quotient in from carry
;; HL holds remainder
adc     hl,hl           ; HL < 2^(7+9), no carry, ever.

;; If remainder is >= divisor, next bit of quotient is 1. We try
;;  to compute the difference.
sbc     hl,de
jr      NC,nodrop      ; Jump if remainder is >= dividend
add     hl,de           ; Otherwise, restore remainder
;; The add above sets the carry, because sbc hl,de did set it.
.nodrop
ccf                     ; Complement borrow so 1 indicates a
;  successful substraction (this is the
;  next bit of quotient)
rla
djnz    dvloop
;; Take care of the ninth quotient bit! after the loop B=0.
rl      b               ; BA = quotient
;; Carry now contains "0" = valid result.
ld      d,b
ld      e,a             ; DE = quotient, HL = remainder
ex      de,hl           ; HL = quotient, DE = remainder
ret


--- NEW FILE: modmixed.asm ---
;--------------------------------------------------------------------------
;  modmixed.s
;
;  Copyright (C) 2010, Philipp Klaus Krause
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------
XLIB __modsuchar_rrx_s
XDEF __moduschar_rrx_s
LIB  __div_signexte
LIB  __get_remainder
LIB __div16

__modsuchar_rrx_s:
ld      hl,#2+1
add     hl,sp

ld      e,(hl)
dec     hl
ld      l,(hl)
ld      h,#0

call    __div_signexte

jp    __get_remainder

__moduschar_rrx_s:
ld      hl,#2+1
ld      d, h
add     hl,sp

ld      e,(hl)
dec     hl
ld      l,(hl)

ld      a,l             ; Sign extend
rlca
sbc     a
ld      h,a

call    __div16

jp    __get_remainder


--- NEW FILE: modsigned.asm ---
;--------------------------------------------------------------------------
;  modsigned.s
;
;  Copyright (C) 2009, Philipp Klaus Krause
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

XLIB __modschar_rrx_s
XDEF __modschar_rrx_hds
LIB  __div8
LIB __get_remainder
XDEF __modsint_rrx_s
XDEF __modsint_rrx_hds
LIB __div16

__modschar_rrx_s:
ld      hl,#2+1
add     hl,sp

ld      e,(hl)
dec     hl
ld      l,(hl)

;; Fall through
__modschar_rrx_hds:
call    __div8

jp    __get_remainder

__modsint_rrx_s:
pop     af
pop     hl
pop     de
push    de
push    hl
push    af

;; Fall through
__modsint_rrx_hds:
call    __div16

jp    __get_remainder


--- NEW FILE: modunsigned.asm ---
;--------------------------------------------------------------------------
;  modunsigned.s
;
;  Copyright (C) 2009-2010, Philipp Klaus Krause
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

XLIB __moduchar_rrx_s
XDEF __moduchar_rrx_hds
XDEF __moduint_rrx_s
LIB __divunsigned
LIB __divu8
LIB  __divu16
XDEF __moduint_rrx_s
XDEF __moduint_rrx_hds


__moduchar_rrx_s:
ld      hl,#2+1
add     hl,sp

ld      e,(hl)
dec     hl
ld      l,(hl)

;; Fall through
__moduchar_rrx_hds:
call    __divu8

ex    de,hl

ret

__moduint_rrx_s:
pop     af
pop     hl
pop     de
push    de
push    hl
push    af

;; Fall through
__moduint_rrx_hds:
call    __divu16

ex      de,hl

ret


--- NEW FILE: mul.asm ---
;--------------------------------------------------------------------------
;  mulchar.s
;
;  Copyright (C) 2000, Michael Hope
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------


XLIB __mulint_rrx_s
XDEF __muluchar_rrx_hds
XDEF __mulint_rrx_hds
XDEF __mul16

__mulint_rrx_s:
pop     af
pop     hl
pop     de
push    de
push    hl
push    af

;; Fall through

__muluchar_rrx_hds:
__mulint_rrx_hds:
;; Parameters:
;;    hl, de (left, right irrelevant)
ld    b,h
ld    c,l

;; 16-bit multiplication
;;
;; Entry conditions
;; bc = multiplicand
;; de = multiplier
;;
;; Exit conditions
;; hl = less significant word of product
;;
;; Register used: AF,BC,DE,HL
__mul16:
xor    a,a
ld    l,a
or    a,b
ld    b,#16

;; Optimise for the case when this side has 8 bits of data or
;; less.  This is often the case with support address calls.
jr      NZ,lab2
ld      b,#8
ld      a,c
.lab1
;; Taken from z88dk, which originally borrowed from the
;; Spectrum rom.
add     hl,hl
.lab2
rl      c
rla                     ;DLE 27/11/98
jr      NC,lab3
add     hl,de
.lab3
djnz    lab1
ret


--- NEW FILE: mulchar.asm ---
;--------------------------------------------------------------------------
;  mulchar.s
;
;  Copyright (C) 2009, Philipp Klaus Krause
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

XLIB __muluchar_rrx_s
XDEF __mulsuchar_rrx_s
XDEF __muluschar_rrx_s
XDEF __mulschar_rrx_s
XDEF __mulschar_rrx_hds
LIB  __mul16

; 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
ld      d, h
add     hl, sp
ld      e, (hl)
dec     hl
ld      h, (hl)
ld      l, d
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
ld      b, h
add     hl,sp

ld      e,(hl)
dec     hl
ld      c,(hl)
jr      signexte

__muluschar_rrx_s:
ld      hl,#2
ld      b, h
add     hl,sp

ld      e,(hl)
inc     hl
ld      c,(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


--- NEW FILE: shift.asm ---
;--------------------------------------------------------------------------
;  putchar.s
;
;  Copyright (C) 2001, Michael Hope
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2.1, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;--------------------------------------------------------------------------
XLIB __rrulong_rrx_s
XDEF __rrslong_rrx_s
XDEF __rlslong_rrx_s
XDEF __rlulong_rrx_s

__rrulong_rrx_s:
ld      hl,#2+4
add     hl,sp

ld      a,(hl)
or      a,a
pop     bc
pop     hl
pop     de
push    de
push    hl
push    bc
ret     Z
ld      b,a
ld      a,e
.lab1
srl     d
rra
rr    h
rr      l

djnz    lab1
ld      e,a
ret

__rrslong_rrx_s:
ld      hl,#2+4
add     hl,sp

ld      a,(hl)
or      a,a
pop     bc
pop     hl
pop     de
push    de
push    hl
push    bc
ret     Z
ld      b,a
ld      a,e
.lab2
sra     d
rra
rr    h
rr      l

djnz    lab2
ld      e,a
ret

__rlslong_rrx_s:
__rlulong_rrx_s:
ld      hl,#2+4
add     hl,sp

ld      a,(hl)
or      a,a
pop     bc
pop     hl
pop     de
push    de
push    hl
push    bc
ret     Z
ld      b,a
ld      a,e
lab3:
add     hl,hl
rla
rl    d

djnz    lab3
ld      e,a
ret


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev

 
  • Index
  •  » z88dk-commits
  •  » [Z88dk-commits] CVS: z88dk/libsrc/z80_crt0s/crt0_sdcc divmixed.asm,

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson