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)
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
62 _muluint (unsigned int a, unsigned int b) // in future: _mulint
64 a*b; // hush the compiler
68 (char)(msb_a*lsb_b)<<8 +
69 (char)(lsb_a*msb_b)<<8
77 mov dptr,#__muluint_PARM_2
102 _mulsint (int a, int b) // obsolete
104 return _muluint (a, b);
107 #elif defined _MULINT_ASM_SMALL || defined _MULINT_ASM_SMALL_AUTO
110 _mulint_dummy (void) _naked
115 __muluint: ; obsolete
116 __mulsint: ; obsolete
119 .globl __muluint ; obsolete
120 .globl __mulsint ; obsolete
122 #if !defined(SDCC_STACK_AUTO)
124 #if defined(SDCC_NOOVERLAY) // BUG SDCC_NOOVERLAY is not set by -no-overlay
127 .area OSEG (OVR,DATA)
131 __muluint_PARM_2: ; obsolete
132 __mulsint_PARM_2: ; obsolete
134 .globl __mulint_PARM_2
135 .globl __muluint_PARM_2 ; obsolete
136 .globl __mulsint_PARM_2 ; obsolete
142 ; globbered registers none
145 mov b,__mulint_PARM_2 ; 2 bl
147 xch a,dpl ; 1 store low-byte of return value, fetch al
150 mov b,__mulint_PARM_2 + 1 ; 2 bh
154 xch a,dph ; 1 ah -> acc
156 mov b,__mulint_PARM_2 ; 2 bl
163 #else // SDCC_STACK_AUTO
165 ; globbered registers r0
167 mov a,#-2 ; 1 return address 2 bytes
169 mov r0,a ; 1 r0 points to bh
181 mov dpl,a ; 1 low-byte of return-value
185 xch a,dph ; 1 ah -> acc
194 #endif // SDCC_STACK_AUTO
202 struct { unsigned char lo,hi ;} s;
207 _muluint (unsigned int a, unsigned int b) // in future: _mulint
209 #ifdef SDCC_MODEL_LARGE // still needed for large + stack-auto
213 x = (union uu xdata *)&a;
214 y = (union uu xdata *)&b;
216 register union uu *x;
217 register union uu *y;
223 t.t = x->s.lo * y->s.lo;
224 t.s.hi += (x->s.lo * y->s.hi) + (x->s.hi * y->s.lo);
230 _mulsint (int a, int b) // obsolete
232 return _muluint (a, b);