1 /*-------------------------------------------------------------------------
2 _moduint.c - routine for unsigned int (16 bit) modulus
4 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
5 Bug fixes by Martijn van Balen, aed@iae.nl
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 /* Assembler-functions are provided for:
32 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)
41 # define _MODUINT_ASM_SMALL_AUTO
43 # define _MODUINT_ASM_SMALL
49 #if defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO
52 _moduint_dummy (void) __naked
64 #if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1)
66 ar0
= 0 ; BUG
register set is
not considered
72 add a
,#-2 ; 2 bytes return address
73 mov r0
,a
; r0 points to bh
81 __modint
: ; entry point
for __modsint
84 #else // __SDCC_STACK_AUTO
86 #if !defined(__SDCC_PARMS_IN_BANK1)
87 #if defined(__SDCC_NOOVERLAY)
93 .globl __moduint_PARM_2
94 .globl __modsint_PARM_2
102 #define bl (__moduint_PARM_2)
103 #define bh (__moduint_PARM_2 + 1)
108 #endif // __SDCC_STACK_AUTO
110 mov a
,bl
; avoid endless loop
116 loop1
: mov a
,bl
; b
<<= 1
125 subb a
,bl
; here carry is always clear
152 mov ah
,a
; -> yes
; a
= a
- b
;
170 #else // defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO
172 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
175 _moduint (unsigned int a
, unsigned int b
) __SDCC_NONBANKED
177 unsigned char count
= 0;
199 #endif // defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO