1 /*-------------------------------------------------------------------------
2 _divsint.c :- routine for signed int (16 bit) division. just calls
3 routine for unsigned division after sign adjustment
5 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
33 #if _SDCC_MANGLES_SUPPORT_FUNS
34 unsigned unsigned _divuint (unsigned x
, unsigned y
);
37 /* Assembler-functions are provided for:
39 mcs51 small stack-auto
42 #if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
43 # if defined(__SDCC_mcs51)
44 # if defined(__SDCC_MODEL_SMALL)
45 # if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1)
46 # define _DIVSINT_ASM_SMALL_AUTO
48 # define _DIVSINT_ASM_SMALL
54 #if defined _DIVSINT_ASM_SMALL
57 _divsint_dummy (void) __naked
66 // _divsint_PARM_2 shares the same memory with _divuint_PARM_2
67 // and is defined in _divuint.c
68 #if defined(__SDCC_PARMS_IN_BANK1)
72 #define yl (__divsint_PARM_2)
73 #define yh (__divsint_PARM_2 + 1)
77 ; yh
in (__divsint_PARM_2
+ 1)
79 clr F0
; Flag
0 in PSW
80 ; available to user
for general purpose
82 jnb acc
.7,a_not_negative
97 jnb acc
.7,b_not_negative
129 #elif defined _DIVSINT_ASM_SMALL_AUTO
132 _divsint_dummy (void) __naked
143 clr F0
; Flag
0 in PSW
144 ; available to user
for general purpose
146 jnb acc
.7,a_not_negative
161 add a
,#-2 ; 2 bytes return address
162 mov r0
,a
; r0 points to yh
165 jnb acc
.7,b_not_negative
204 #else // _DIVSINT_ASM_
207 _divsint (int x
, int y
) __SDCC_NONBANKED
211 r
= (unsigned int)(x
< 0 ? -x
: x
) / (unsigned int)(y
< 0 ? -y
: y
);
212 if ((x
< 0) ^ (y
< 0))
218 #endif // _DIVSINT_ASM_