1 /*-------------------------------------------------------------------------
2 _modslong.c - routine for modulus of 32 bit signed long
4 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU 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 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
31 #if _SDCC_MANGLES_SUPPORT_FUNS
32 unsigned long _modulong (unsigned long a
, unsigned long b
);
35 /* Assembler-functions are provided for:
37 mcs51 small stack-auto
40 #if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
41 # if defined(__SDCC_mcs51)
42 # if defined(__SDCC_MODEL_SMALL)
43 # if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1)
44 # define _MODSLONG_ASM_SMALL_AUTO
46 # define _MODSLONG_ASM_SMALL
52 #if defined _MODSLONG_ASM_SMALL
55 _modslong_dummy (void) __naked
65 #if defined(__SDCC_PARMS_IN_BANK1)
71 // _modslong_PARM_2 shares the same memory with _modulong_PARM_2
72 // and is defined in _modulong.c
73 #define b0 (__modslong_PARM_2)
74 #define b1 (__modslong_PARM_2 + 1)
75 #define b2 (__modslong_PARM_2 + 2)
76 #define b3 (__modslong_PARM_2 + 3)
80 ; b3
in (__modslong_PARM_2
+ 3)
83 clr F0
; Flag
0 in PSW
84 ; available to user
for general purpose
85 jnb acc
.7,a_not_negative
106 jnb acc
.7,b_not_negative
124 mov a
,a3
; restore a3 in acc
130 ; result
in (a
== r1
), b
, dph
, dpl
143 ; result in a
, b
, dph
, dpl
150 #elif defined _MODSLONG_ASM_SMALL_AUTO
153 _modslong_dummy (void) __naked
167 ar2
= 2 ; BUG
register set is
not considered
180 ; available to user
for general purpose
181 jnb acc
.7,a_not_negative
202 add a
,#-2-3 ; 2 bytes return address, 3 bytes param b
203 mov r0
,a
; r1 points to b0
205 mov ar2
,@r0
; load b0
206 inc r0
; r0 points to b1
214 jnb acc
.7,b_not_negative
236 ; result
in (a
== r1
), b
, dph
, dpl
248 subb a
,a3
; result in a
, b
, dph
, dpl
256 #else // _MODSLONG_ASM
259 _modslong (long a
, long b
) __SDCC_NONBANKED
263 r
= (unsigned long)(a
< 0 ? -a
: a
) % (unsigned long)(b
< 0 ? -b
: b
);
271 #endif // _MODSLONG_ASM