1 /*-------------------------------------------------------------------------
2 _mulint.c :- routine for (unsigned) int (16 bit) multiplication
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (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 /* Signed and unsigned multiplication are the same - as long as the output
26 has the same precision as the input.
28 To do: _muluint and _mulsint should be replaced by _mulint.
30 bernhard@bernhardheld.de
32 Assembler-functions are provided for:
35 mcs51 small stack-auto
39 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
40 # if defined(SDCC_ds390)
41 # if !defined(SDCC_STACK_AUTO)
42 # define _MULINT_ASM_LARGE
44 # elif defined(SDCC_mcs51)
45 # if defined(SDCC_MODEL_SMALL)
46 # if defined(SDCC_STACK_AUTO) && !defined(SDCC_PARMS_IN_BANK1)
47 # define _MULINT_ASM_SMALL_AUTO
49 # define _MULINT_ASM_SMALL
51 # else // must be SDCC_MODEL_LARGE
52 # if !defined(SDCC_STACK_AUTO)
53 # define _MULINT_ASM_LARGE
59 #ifdef _MULINT_ASM_LARGE
64 _muluint (unsigned int a, unsigned int b) // in future: _mulint
66 a*b; // hush the compiler
70 (char)(msb_a*lsb_b)<<8 +
71 (char)(lsb_a*msb_b)<<8
79 #if defined(SDCC_PARMS_IN_BANK1)
82 mov dptr,#__muluint_PARM_2
90 #if defined(SDCC_PARMS_IN_BANK1)
100 #if defined(SDCC_PARMS_IN_BANK1)
117 _mulsint (int a, int b) // obsolete
119 return _muluint (a, b);
122 #elif defined _MULINT_ASM_SMALL || defined _MULINT_ASM_SMALL_AUTO
125 #pragma LESS_PEDANTIC
127 _mulint_dummy (void) _naked
132 __muluint: ; obsolete
133 __mulsint: ; obsolete
136 .globl __muluint ; obsolete
137 .globl __mulsint ; obsolete
139 #if !defined(SDCC_STACK_AUTO) || defined(SDCC_PARMS_IN_BANK1)
141 #if defined(SDCC_NOOVERLAY)
144 .area OSEG (OVR,DATA)
146 #if defined(SDCC_PARMS_IN_BANK1)
150 #define bl (__mulint_PARM_2)
151 #define bh (__mulint_PARM_2 + 1)
153 __muluint_PARM_2: ; obsolete
154 __mulsint_PARM_2: ; obsolete
156 .globl __mulint_PARM_2
157 .globl __muluint_PARM_2 ; obsolete
158 .globl __mulsint_PARM_2 ; obsolete
165 ; globbered registers none
170 xch a,dpl ; 1 store low-byte of return value, fetch al
177 xch a,dph ; 1 ah -> acc
186 #else // SDCC_STACK_AUTO
188 ; globbered registers r0
190 mov a,#-2 ; 1 return address 2 bytes
192 mov r0,a ; 1 r0 points to bh
204 mov dpl,a ; 1 low-byte of return-value
208 xch a,dph ; 1 ah -> acc
217 #endif // SDCC_STACK_AUTO
226 struct { unsigned char lo,hi ;} s;
231 _muluint (unsigned int a, unsigned int b) // in future: _mulint
233 #if !defined(SDCC_STACK_AUTO) && (defined(SDCC_MODEL_LARGE) || defined(SDCC_ds390)) // still needed for large
237 x = (union uu xdata *)&a;
238 y = (union uu xdata *)&b;
240 register union uu *x;
241 register union uu *y;
247 t.t = x->s.lo * y->s.lo;
248 t.s.hi += (x->s.lo * y->s.hi) + (x->s.hi * y->s.lo);
254 _mulsint (int a, int b) // obsolete
256 return _muluint (a, b);