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) && !defined(SDCC_PARMS_IN_BANK1)
40 # define _MODSLONG_ASM_SMALL_AUTO
42 # define _MODSLONG_ASM_SMALL
48 #if defined _MODSLONG_ASM_SMALL
51 _modslong_dummy (void) _naked
61 #if defined(SDCC_PARMS_IN_BANK1)
67 // _modslong_PARM_2 shares the same memory with _modulong_PARM_2
68 // and is defined in _modulong.c
69 #define b0 (__modslong_PARM_2)
70 #define b1 (__modslong_PARM_2 + 1)
71 #define b2 (__modslong_PARM_2 + 2)
72 #define b3 (__modslong_PARM_2 + 3)
76 ; b3 in (__modslong_PARM_2 + 3)
79 clr F0 ; Flag 0 in PSW
80 ; available to user for general purpose
81 jnb acc.7,a_not_negative
102 jnb acc.7,b_not_negative
122 mov a,a3 ; restore a3 in acc
128 ; result in (a == r1), b, dph, dpl
141 ; result in a, b, dph, dpl
148 #elif defined _MODSLONG_ASM_SMALL_AUTO
151 _modslong_dummy (void) _naked
165 ar2 = 2 ; BUG register set is not considered
178 ; available to user for general purpose
179 jnb acc.7,a_not_negative
200 add a,#-2-3 ; 2 bytes return address, 3 bytes param b
201 mov r0,a ; r1 points to b0
204 mov ar2,@r0 ; load b0
205 inc r0 ; r0 points to b1
213 jnb acc.7,b_not_negative
237 ; result in (a == r1), b, dph, dpl
249 subb a,a3 ; result in a, b, dph, dpl
257 #else // _MODSLONG_ASM
260 _modslong (long a, long b)
264 r = _modulong((a < 0 ? -a : a),
266 if ( (a < 0) ^ (b < 0))
272 #endif // _MODSLONG_ASM