struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / z80n / mul.s
blob5cd6ae70a0ad30fb61d8fea78ea094151e189aa2
1 ;--------------------------------------------------------------------------
2 ; mul.s
4 ; Copyright (C) 2000, Michael Hope
5 ; Copyright (C) 2021, Philipp Klaus Krause
6 ; Copyright (C) 2024, Peter Ped Helcmanovsky
7 ; Copyright (C) 2024, Janko Stamenović
9 ; This library is free software; you can redistribute it and/or modify it
10 ; under the terms of the GNU General Public License as published by the
11 ; Free Software Foundation; either version 2, or (at your option) any
12 ; later version.
14 ; This library is distributed in the hope that it will be useful,
15 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ; GNU General Public License for more details.
19 ; You should have received a copy of the GNU General Public License
20 ; along with this library; see the file COPYING. If not, write to the
21 ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 ; MA 02110-1301, USA.
24 ; As a special exception, if you link this library with other files,
25 ; some of which are compiled with SDCC, to produce an executable,
26 ; this library does not by itself cause the resulting executable to
27 ; be covered by the GNU General Public License. This exception does
28 ; not however invalidate any other reasons why the executable file
29 ; might be covered by the GNU General Public License.
30 ;--------------------------------------------------------------------------
32 .zxn
34 .area _CODE
36 .globl __mulint
38 __mulint:
39 __mul16_HL_DE_to_DE::
40 ;; unsigned _mulint (unsigned m, unsigned n) __sdcccall(1);
42 ;; 16-bit multiplication
44 ;; Entry conditions
45 ;; hl = multiplicand
46 ;; de = multiplier
48 ;; Exit conditions
49 ;; de = less significant word of product
51 ;; Registers used: AF, C,DE,HL
53 ; Goal: DE := H_0 L_0 * D_0 E_0
54 ; (_0 inital content of the registers,
55 ; 16-bit register pairs contain
56 ; 16-bit values to be multiplied.)
58 ; see also: mul_16_16_16_AE (CC0)
59 ld c, e
60 ld e, l
61 mlt de ;
62 ld a, e ; A = LOWBYTE( D_O*L_0 )
63 ld e, c
64 ld d, h
65 mlt de ;
66 add a, e ; A += LOWBYTE( E_0*H_0 )
67 ld e, c
68 ld d, l
69 mlt de ; DE = E_0*L_0
70 add a, d ; A += HIGHBYTE( E_0*L_0 )
71 ld d, a
72 ; total: 64T to here
73 ; D = the upper product byte, summed
74 ; E = LOW( E_0*L_0 )
75 ret