1 /*-------------------------------------------------------------------------
2 _moduint.c :- routine for unsigned int (16 bit) modulus
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 Bug fixes by Martijn van Balen, aed@iae.nl
8 This library is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Library General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 In other words, you are welcome to use, share and improve this program.
23 You are forbidden to forbid anyone else to use, share and improve
24 what you give them. Help stamp out software-hoarding!
25 -------------------------------------------------------------------------*/
27 /* Assembler-functions are provided for:
29 mcs51 small stack-auto
32 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
33 # if defined(SDCC_mcs51)
34 # if defined(SDCC_MODEL_SMALL)
35 # if defined(SDCC_STACK_AUTO)
36 # define _MODUINT_ASM_SMALL_AUTO
38 # define _MODUINT_ASM_SMALL
44 #if defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO
47 _moduint_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 __modint: ; entry point for __modsint
79 #else // SDCC_STACK_AUTO
81 #if !defined(SDCC_PARMS_IN_BANK1)
82 #if defined(SDCC_NOOVERLAY)
88 .globl __moduint_PARM_2
89 .globl __modsint_PARM_2
97 #define bl (__moduint_PARM_2)
98 #define bh (__moduint_PARM_2 + 1)
103 #endif // SDCC_STACK_AUTO
105 mov a,bl ; avoid endless loop
111 loop1: mov a,bl ; b <<= 1
120 subb a,bl ; here carry is always clear
147 mov ah,a ; -> yes; a = a - b;
165 #else // defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO
167 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
170 _moduint (unsigned int a, unsigned int b)
172 unsigned char count = 0;
195 #endif // defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO