1 /*-------------------------------------------------------------------------
2 _divuint.c :- routine for unsigned int (16 bit) division
4 Ecrit par - Jean-Louis Vern . jlvern@writeme.com (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 -------------------------------------------------------------------------*/
25 /* Assembler-functions are provided for:
27 mcs51 small stack-auto
30 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
31 # if defined(SDCC_mcs51)
32 # if defined(SDCC_MODEL_SMALL)
33 # if defined(SDCC_STACK_AUTO)
34 # define _DIVUINT_ASM_SMALL_AUTO
36 # define _DIVUINT_ASM_SMALL
42 #if defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO
45 _divuint_dummy (void) _naked
59 #if defined(SDCC_STACK_AUTO) && !defined(SDCC_PARMS_IN_BANK1)
61 ar0 = 0 ; BUG register set is not considered
67 add a,#-2 ; 2 bytes return address
68 mov r0,a ; r0 points to bh
76 __divint: ; entry point for __divsint
79 #else // SDCC_STACK_AUTO
81 #if !defined(SDCC_PARMS_IN_BANK1)
82 #if defined(SDCC_NOOVERLAY)
88 .globl __divuint_PARM_2
89 .globl __divsint_PARM_2
96 #endif // !SDCC_PARMS_IN_BANK1
97 #if defined(SDCC_PARMS_IN_BANK1)
101 #define bl (__divuint_PARM_2)
102 #define bh (__divuint_PARM_2 + 1)
103 #endif // SDCC_PARMS_IN_BANK1
104 #endif // SDCC_STACK_AUTO
111 loop: mov a,al ; a <<= 1
118 mov a,reste_l ; reste <<= 1
119 rlc a ; feed in carry
125 mov a,reste_l ; reste - b
126 subb a,bl ; here carry is always clear, because
127 ; reste <<= 1 never overflows
132 jc smaller ; reste >= b?
134 mov reste_h,a ; -> yes; reste = reste - b;
144 #else // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO
146 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
149 _divuint (unsigned int a, unsigned int b)
151 unsigned int reste = 0;
152 unsigned char count = 16;
153 #if defined(SDCC_STACK_AUTO) || defined(SDCC_z80)
179 #endif // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO