4defb60ebc9560915cf2f3e75e61cb841fce8b34
[fw/sdcc] / device / lib / _divsint.c
1 /*-------------------------------------------------------------------------
2
3   _divsint.c :- routine for signed int (16 bit) division. just calls
4                 routine for unsigned division after sign adjustment
5
6              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
7
8    This program is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published by the
10    Free Software Foundation; either version 2, or (at your option) any
11    later version.
12    
13    This program 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 General Public License for more details.
17    
18    You should have received a copy of the GNU 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.
21    
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 -------------------------------------------------------------------------*/
26 int _divsint (int a, int b)
27 #ifndef SDCC_STACK_AUTO
28         critical
29 #endif
30 {
31        register int r;
32       
33        r = _divuint((a < 0 ? -a : a),
34                     (b < 0 ? -b : b));
35        if ( (a < 0) ^ (b < 0)) {
36         
37             return -r;
38         }
39         else {
40
41             return r;
42         }
43 }