1 /*-------------------------------------------------------------------------
2 _modsint.c - routine for signed int (16 bit) modulus
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 -------------------------------------------------------------------------*/
32 #if _SDCC_MANGLES_SUPPORT_FUNS
33 unsigned unsigned _moduint (unsigned a
, unsigned b
);
36 /* Assembler-functions are provided for:
38 mcs51 small stack-auto
41 #if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
42 # if defined(__SDCC_mcs51)
43 # if defined(__SDCC_MODEL_SMALL)
44 # if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1)
45 # define _MODSINT_ASM_SMALL_AUTO
47 # define _MODSINT_ASM_SMALL
53 #if defined _MODSINT_ASM_SMALL
56 _modsint_dummy (void) __naked
64 #if defined(__SDCC_PARMS_IN_BANK1)
68 // _modsint_PARM_2 shares the same memory with _moduint_PARM_2
69 // and is defined in _moduint.c
70 #define b0 (__modsint_PARM_2)
71 #define b1 (__modsint_PARM_2 + 1)
75 ; b1
in (__modsint_PARM_2
+ 1)
77 clr F0
; Flag
0 in PSW
78 ; available to user
for general purpose
80 jnb acc
.7,a_not_negative
95 jnb acc
.7,b_not_negative
125 #elif defined _MODSINT_ASM_SMALL_AUTO
128 _modsint_dummy (void) __naked
135 ar0
= 0 ; BUG
register set is
not considered
142 clr F0
; Flag
0 in PSW
143 ; available to user
for general purpose
145 jnb acc
.7,a_not_negative
160 add a
,#-2 ; 2 bytes return address
161 mov r0
,a
; r0 points to b1
164 jnb acc
.7,b_not_negative
201 #else // _MODSINT_ASM_
203 int _modsint (int a
, int b
) __SDCC_NONBANKED
207 r
= (unsigned)(a
< 0 ? -a
: a
) % (unsigned)(b
< 0 ? -b
: b
);
215 #endif // _MODSINT_ASM_