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