1 /*-------------------------------------------------------------------------
2 _divsint.c :- routine for signed int (16 bit) division. just calls
3 routine for unsigned division after sign adjustment
5 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Library 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 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
29 #if _SDCC_MANGLES_SUPPORT_FUNS
30 unsigned unsigned _divuint (unsigned x, unsigned y);
33 /* Assembler-functions are provided for:
35 mcs51 small stack-auto
38 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
39 # if defined(SDCC_mcs51)
40 # if defined(SDCC_MODEL_SMALL)
41 # if defined(SDCC_STACK_AUTO) && !defined(SDCC_PARMS_IN_BANK1)
42 # define _DIVSINT_ASM_SMALL_AUTO
44 # define _DIVSINT_ASM_SMALL
50 #if defined _DIVSINT_ASM_SMALL
53 _divsint_dummy (void) __naked
62 // _divsint_PARM_2 shares the same memory with _divuint_PARM_2
63 // and is defined in _divuint.c
64 #if defined(SDCC_PARMS_IN_BANK1)
68 #define yl (__divsint_PARM_2)
69 #define yh (__divsint_PARM_2 + 1)
73 ; yh in (__divsint_PARM_2 + 1)
75 clr F0 ; Flag 0 in PSW
76 ; available to user for general purpose
78 jnb acc.7,a_not_negative
93 jnb acc.7,b_not_negative
125 #elif defined _DIVSINT_ASM_SMALL_AUTO
128 _divsint_dummy (void) __naked
139 clr F0 ; Flag 0 in PSW
140 ; available to user for general purpose
142 jnb acc.7,a_not_negative
157 add a,#-2 ; 2 bytes return address
158 mov r0,a ; r0 points to yh
161 jnb acc.7,b_not_negative
200 #else // _DIVSINT_ASM_
203 _divsint (int x, int y)
207 r = _divuint((x < 0 ? -x : x),
209 if ( (x < 0) ^ (y < 0))
215 #endif // _DIVSINT_ASM_