struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / stm8-large / __mulsint2slong.s
blobc6f5afa76e182ae0a9ba036194cc11c0eeb9d3a2
1 ;--------------------------------------------------------------------------
2 ; __mulsint2slong.s
4 ; Copyright (C) 2016-2021, Philipp Klaus Krause
6 ; This library is free software; you can redistribute it and/or modify it
7 ; under the terms of the GNU General Public License as published by the
8 ; Free Software Foundation; either version 2, or (at your option) any
9 ; later version.
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 General Public License for more details.
16 ; You should have received a copy of the GNU General Public License
17 ; along with this library; see the file COPYING. If not, write to the
18 ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 ; MA 02110-1301, USA.
21 ; As a special exception, if you link this library with other files,
22 ; some of which are compiled with SDCC, to produce an executable,
23 ; this library does not by itself cause the resulting executable to
24 ; be covered by the GNU General Public License. This exception does
25 ; not however invalidate any other reasons why the executable file
26 ; might be covered by the GNU General Public License.
27 ;--------------------------------------------------------------------------
29 .globl ___mulsint2slong
30 .globl ___muluint2ulong
32 .area CODE
34 ___muluint2ulong:
35 pushw x
37 clr a
38 ldw x, (6, sp)
39 jra right_nonneg
41 ___mulsint2slong:
42 pushw x
44 ; Handle signed operands
45 clr a
46 tnzw x
47 jrpl left_nonneg
48 cpl a
49 negw x
50 ldw (1, sp), x
51 left_nonneg:
52 ldw x, (6, sp)
53 jrpl right_nonneg
54 cpl a
55 negw x
56 ldw (6, sp), x
57 right_nonneg:
59 sub sp, #4
60 push a
62 ; Multiply lower bytes
63 ld a, (5+2, sp)
64 mul x, a
65 ldw (4, sp), x
67 ; Multiply upper bytes
68 ldw x, (5+0, sp)
69 ld a, (5+6, sp)
70 mul x, a
71 ldw (2, sp), x
73 ; Multiply middle bytes
74 ld a, (5+6, sp)
75 jreq skip_m1
76 ldw x, (5+1, sp)
77 mul x, a
78 addw x, (3, sp)
79 ldw (3, sp), x
80 ld a, (2, sp)
81 adc a, #0
82 ld (2, sp), a
83 skip_m1:
85 ld a, (5+1, sp)
86 jreq skip_m2
87 ldw x, (5+6, sp)
88 mul x, a
89 addw x, (3, sp)
90 ldw (3, sp), x
91 ld a, (2, sp)
92 adc a, #0
93 ld (2, sp), a
94 skip_m2:
96 ; Handle signed result
97 pop a
98 popw y
99 popw x
100 tnz a
101 jrpl end
102 negw x
103 jrnc neg_y
104 incw y
105 neg_y:
106 negw y
107 end:
108 addw sp, #2
109 retf