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 a, unsigned b);
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)
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 #define b0 (__divsint_PARM_2)
65 #define b1 (__divsint_PARM_2 + 1)
69 ; b1 in (__divsint_PARM_2 + 1)
71 clr F0 ; Flag 0 in PSW
72 ; available to user for general purpose
74 jnb acc.7,a_not_negative
89 jnb acc.7,b_not_negative
121 #elif defined _DIVSINT_ASM_SMALL_AUTO
124 _divsint_dummy (void) _naked
131 ar0 = 0 ; BUG register set is not considered
138 clr F0 ; Flag 0 in PSW
139 ; available to user for general purpose
141 jnb acc.7,a_not_negative
156 add a,#-2 ; 2 bytes return address
157 mov r0,a ; r0 points to b1
160 jnb acc.7,b_not_negative
199 #else // _DIVSINT_ASM_
202 _divsint (int a, int b)
206 r = _divuint((a < 0 ? -a : a),
208 if ( (a < 0) ^ (b < 0))
214 #endif // _DIVSINT_ASM_