1 /*-------------------------------------------------------------------------
2 _modsint.c :- routine for signed int (16 bit) modulus
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
28 #if _SDCC_MANGLES_SUPPORT_FUNS
29 unsigned unsigned _moduint (unsigned a, unsigned b);
32 /* Assembler-functions are provided for:
34 mcs51 small stack-auto
37 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
38 # if defined(SDCC_mcs51)
39 # if defined(SDCC_MODEL_SMALL)
40 # if defined(SDCC_STACK_AUTO)
41 # define _MODSINT_ASM_SMALL_AUTO
43 # define _MODSINT_ASM_SMALL
49 #if defined _MODSINT_ASM_SMALL
52 _modsint_dummy (void) _naked
61 // _modsint_PARM_2 shares the same memory with _moduint_PARM_2
62 // and is defined in _moduint.c
63 #define b0 (__modsint_PARM_2)
64 #define b1 (__modsint_PARM_2 + 1)
68 ; b1 in (__modsint_PARM_2 + 1)
70 clr F0 ; Flag 0 in PSW
71 ; available to user for general purpose
73 jnb acc.7,a_not_negative
88 jnb acc.7,b_not_negative
120 #elif defined _MODSINT_ASM_SMALL_AUTO
123 _modsint_dummy (void) _naked
130 ar0 = 0 ; BUG register set is not considered
137 clr F0 ; Flag 0 in PSW
138 ; available to user for general purpose
140 jnb acc.7,a_not_negative
155 add a,#-2 ; 2 bytes return address
156 mov r0,a ; r0 points to b1
159 jnb acc.7,b_not_negative
198 #else // _MODSINT_ASM_
200 int _modsint (int a, int b)
204 r = _moduint((a < 0 ? -a : a),
207 if ( (a < 0) ^ (b < 0))
213 #endif // _MODSINT_ASM_