Minor improvements, code cleanup and license clarification
[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         ;; hl = less significant word of product
33         ;;
34         ;; Register used: AF,BC,DE,HL
35 __mul16::
36         xor     a,a
37         ld      l,a
38         or      a,b
39         ld      b,#16
40
41         ;; Optimise for the case when this side has 8 bits of data or
42         ;; less.  This is often the case with support address calls.
43         jr      NZ,2$
44         ld      b,#8
45         ld      a,c
46 1$:
47         ;; Taken from z88dk, which originally borrowed from the
48         ;; Spectrum rom.
49         add     hl,hl
50 2$:
51         rl      c
52         rla                     ;DLE 27/11/98
53         jr      NC,3$
54         add     hl,de
55 3$:
56         djnz    1$
57         ret
58