Applied patch #2762516
[fw/sdcc] / device / lib / z80 / mul.s
1         .area   _CODE
2
3 __mulint_rrx_s::
4         pop     af
5         pop     hl
6         pop     de
7         push    de
8         push    hl
9         push    af
10
11         ;; Fall through
12
13 __muluchar_rrx_hds::
14 __mulint_rrx_hds::
15         ;; Parameters:
16         ;;      hl, de (left, right irrelevant)
17         ld      b,h
18         ld      c,l
19
20         ;; 16-bit multiplication
21         ;;
22         ;; Entry conditions
23         ;; bc = multiplicand
24         ;; de = multiplier
25         ;;
26         ;; Exit conditions
27         ;; hl = less significant word of product
28         ;;
29         ;; Register used: AF,BC,DE,HL
30 __mul16::
31         xor     a,a
32         ld      l,a
33         or      a,b
34         ld      b,#16
35
36         ;; Optimise for the case when this side has 8 bits of data or
37         ;; less.  This is often the case with support address calls.
38         jr      NZ,2$
39         ld      b,#8
40         ld      a,c
41 1$:
42         ;; Taken from z88dk, which originally borrowed from the
43         ;; Spectrum rom.
44         add     hl,hl
45 2$:
46         rl      c
47         rla                     ;DLE 27/11/98
48         jr      NC,3$
49         add     hl,de
50 3$:
51         djnz    1$
52         ret
53