1 /*-------------------------------------------------------------------------
3 _muluint.c :- routine for unsigned int (16 bit) multiplication
5 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Library 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 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
26 #if defined(__ds390) || defined (__mcs51)
28 // we can do this faster and more efficient in assembler
30 unsigned int _muluint (unsigned int a, unsigned int b)
32 a*b; // hush the compiler
36 (char)(msb_a*lsb_b)<<8 +
37 (char)(lsb_a*msb_b)<<8
45 #if defined(SDCC_ds390) || defined(SDCC_MODEL_LARGE)
46 mov dptr,#__muluint_PARM_2
48 #else // must be SDCC_MODEL_SMALL
49 mov a,__muluint_PARM_2 ; lsb_b
56 #if defined(SDCC_ds390) || defined(SDCC_MODEL_LARGE)
58 #else // must be SDCC_MODEL_SMALL
59 mov a,__muluint_PARM_2 ; lsb_b
66 #if defined(SDCC_ds390) || defined(SDCC_MODEL_LARGE)
69 #else // must be SDCC_MODEL_SMALL
70 mov a,1+__muluint_PARM_2 ; msb_b
83 // we have to do it the hard way
86 struct { unsigned char lo,hi ;} s;
90 unsigned int _muluint (unsigned int a, unsigned int b)
98 t.t = x->s.lo * y->s.lo;
99 t.s.hi += (x->s.lo * y->s.hi) + (x->s.hi * y->s.lo);