struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / r800 / __mulsint2slong.s
blob024243914a91b2a6c2ec3a13bba6a57235234a96
1 ;--------------------------------------------------------------------------
2 ; __mulsint2slong.s
4 ; Copyright (c) 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 .module u_16_16_mul
31 .globl ___muluint2ulong
32 .globl ___mulsint2slong
34 ; uint32_t _u_16_16_mul(uint16_t l, uint16_t r);
36 .area _CODE
38 ___mulsint2slong:
39 ; Use lowest bit of c to remember if result needs to be negated. Use b to cache #0.
40 ld bc, #0
42 bit #7, l
43 jr z, hl_nonneg
44 ld a, b
45 sub a, l
46 ld l, a
47 ld a, b
48 sbc a, h
49 ld h, a
50 inc c
51 hl_nonneg:
53 bit #7, e
54 jr z, de_nonneg
55 ld a, b
56 sub a, e
57 ld e, a
58 ld a, b
59 sbc a, d
60 ld d, a
61 inc c
62 de_nonneg:
64 push bc
65 call ___muluint2ulong
66 pop bc
68 bit #0, c
69 ret z
71 ; Negate result.
72 ld a, b
73 sub a, e
74 ld e, a
75 ld a, b
76 sbc a, d
77 ld d, a
78 ld a, b
79 sbc a, l
80 ld l, a
81 ld a, b
82 sbc a, h
83 ld h, a
84 ret
86 ; 16x16->32 multiplication
87 ___muluint2ulong:
88 ld iy, #0
89 ld b, #16
90 loop:
91 add iy, iy
92 adc hl, hl
93 jr NC, skip
94 add iy, de
95 jr NC, skip
96 inc hl
97 skip:
98 djnz loop
99 push iy
100 pop de