1 /*-------------------------------------------------------------------------
2 _divslong.c - routine for division of 32 bit 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 -------------------------------------------------------------------------*/
32 #if _SDCC_MANGLES_SUPPORT_FUNS
33 unsigned long _divulong (unsigned long x
, unsigned long y
);
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 _DIVSLONG_ASM_SMALL_AUTO
47 # define _DIVSLONG_ASM_SMALL
53 #if defined _DIVSLONG_ASM_SMALL
56 _divslong_dummy (void) __naked
67 // _divslong_PARM_2 shares the same memory with _divulong_PARM_2
68 // and is defined in _divulong.c
69 #if defined(__SDCC_PARMS_IN_BANK1)
75 #define y0 (__divslong_PARM_2)
76 #define y1 (__divslong_PARM_2 + 1)
77 #define y2 (__divslong_PARM_2 + 2)
78 #define y3 (__divslong_PARM_2 + 3)
82 ; y3
in (__divslong_PARM_2
+ 3)
85 clr F0
; Flag
0 in PSW
86 ; available to user
for general purpose
87 jnb acc
.7,a_not_negative
108 jnb acc
.7,b_not_negative
128 mov a
,x3
; restore x3 in acc
147 subb a
,x3
; x3 ends in acc
155 #elif defined _DIVSLONG_ASM_SMALL_AUTO
158 _divslong_dummy (void) __naked
174 clr F0
; Flag
0 in PSW
175 ; available to user
for general purpose
176 jnb acc
.7,a_not_negative
197 add a
,#-2 ; 2 bytes return address
198 mov r0
,a
; r0 points to y3
201 jnb acc
.7,b_not_negative
229 dec r0
; r0 points to y0
248 subb a
,x3
; x3 ends in acc
256 #else // _DIVSLONG_ASM
259 _divslong (long x
, long y
) __SDCC_NONBANKED
263 r
= (unsigned long)(x
< 0 ? -x
: x
) / (unsigned long)(y
< 0 ? -y
: y
);
264 if ((x
< 0) ^ (y
< 0))
270 #endif // _DIVSLONG_ASM