1 /*-------------------------------------------------------------------------
2 _divslong.c - routine for division of 32 bit 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 -------------------------------------------------------------------------*/
28 #if _SDCC_MANGLES_SUPPORT_FUNS
29 unsigned long _divulong (unsigned long x, unsigned long y);
32 /* Assembler-functions are provided for:
34 mcs51 small stack-auto
37 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
38 # if defined(SDCC_mcs51)
39 # if defined(SDCC_MODEL_SMALL)
40 # if defined(SDCC_STACK_AUTO) && !defined(SDCC_PARMS_IN_BANK1)
41 # define _DIVSLONG_ASM_SMALL_AUTO
43 # define _DIVSLONG_ASM_SMALL
49 #if defined _DIVSLONG_ASM_SMALL
52 _divslong_dummy (void) __naked
63 // _divslong_PARM_2 shares the same memory with _divulong_PARM_2
64 // and is defined in _divulong.c
65 #if defined(SDCC_PARMS_IN_BANK1)
71 #define y0 (__divslong_PARM_2)
72 #define y1 (__divslong_PARM_2 + 1)
73 #define y2 (__divslong_PARM_2 + 2)
74 #define y3 (__divslong_PARM_2 + 3)
78 ; y3 in (__divslong_PARM_2 + 3)
81 clr F0 ; Flag 0 in PSW
82 ; available to user for general purpose
83 jnb acc.7,a_not_negative
104 jnb acc.7,b_not_negative
124 mov a,x3 ; restore x3 in acc
143 subb a,x3 ; x3 ends in acc
151 #elif defined _DIVSLONG_ASM_SMALL_AUTO
154 _divslong_dummy (void) __naked
170 clr F0 ; Flag 0 in PSW
171 ; available to user for general purpose
172 jnb acc.7,a_not_negative
193 add a,#-2 ; 2 bytes return address
194 mov r0,a ; r0 points to y3
197 jnb acc.7,b_not_negative
225 dec r0 ; r0 points to y0
244 subb a,x3 ; x3 ends in acc
252 #else // _DIVSLONG_ASM
255 _divslong (long x, long y)
259 r = _divulong((x < 0 ? -x : x),
261 if ( (x < 0) ^ (y < 0))
267 #endif // _DIVSLONG_ASM