1 /*-------------------------------------------------------------------------
2 _modslong.c - routine for modulus of 32 bit signed long
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 -------------------------------------------------------------------------*/
27 #if _SDCC_MANGLES_SUPPORT_FUNS
28 unsigned long _modulong (unsigned long a, unsigned long b);
31 /* Assembler-functions are provided for:
33 mcs51 small stack-auto
36 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
37 # if defined(SDCC_mcs51)
38 # if defined(SDCC_MODEL_SMALL)
39 # if defined(SDCC_STACK_AUTO)
40 # define _MODSLONG_ASM_SMALL_AUTO
42 # define _MODSLONG_ASM_SMALL
48 #if defined _MODSLONG_ASM_SMALL
51 _modslong_dummy (void) _naked
62 // _modslong_PARM_2 shares the same memory with _modulong_PARM_2
63 // and is defined in _modulong.c
64 #define b0 (__modslong_PARM_2)
65 #define b1 (__modslong_PARM_2 + 1)
66 #define b2 (__modslong_PARM_2 + 2)
67 #define b3 (__modslong_PARM_2 + 3)
71 ; b3 in (__modslong_PARM_2 + 3)
74 clr F0 ; Flag 0 in PSW
75 ; available to user for general purpose
76 jnb acc.7,a_not_negative
97 jnb acc.7,b_not_negative
117 mov a,a3 ; restore a3 in acc
123 ; result in (a == r1), b, dph, dpl
136 ; result in a, b, dph, dpl
143 #elif defined _MODSLONG_ASM_SMALL_AUTO
146 _modslong_dummy (void) _naked
160 ar2 = 2 ; BUG register set is not considered
173 ; available to user for general purpose
174 jnb acc.7,a_not_negative
195 add a,#-2-3 ; 2 bytes return address, 3 bytes param b
196 mov r0,a ; r1 points to b0
199 mov ar2,@r0 ; load b0
200 inc r0 ; r0 points to b1
208 jnb acc.7,b_not_negative
232 ; result in (a == r1), b, dph, dpl
244 subb a,a3 ; result in a, b, dph, dpl
252 #else // _MODSLONG_ASM
255 _modslong (long a, long b)
259 r = _modulong((a < 0 ? -a : a),
261 if ( (a < 0) ^ (b < 0))
267 #endif // _MODSLONG_ASM