Applied patch #2762516
[fw/sdcc] / device / lib / z80 / mulchar.s
1         .area   _CODE
2
3 ; This multiplication routine is similar to the one
4 ; from Rodnay Zaks, "Programming the Z80".
5
6 ; Now replaced by a builtin for code generation, but
7 ; still called from some asm files in this directory.
8 __muluchar_rrx_s::
9         ld      hl, #2+1
10         ld      d, h
11         add     hl, sp
12         ld      e, (hl)
13         dec     hl
14         ld      h, (hl)
15         ld      l, d
16         ld      b, #8
17 muluchar_rrx_s_loop:
18         add     hl, hl
19         jr      nc, muluchar_rrx_s_noadd
20         add     hl, de
21 muluchar_rrx_s_noadd:
22         djnz    muluchar_rrx_s_loop
23         ret
24
25 ; operands have different sign
26
27 __mulsuchar_rrx_s::
28         ld      hl,#2+1
29         ld      b, h
30         add     hl,sp
31
32         ld      e,(hl)
33         dec     hl
34         ld      c,(hl)
35         jr      signexte
36
37 __muluschar_rrx_s::
38         ld      hl,#2
39         ld      b, h
40         add     hl,sp
41
42         ld      e,(hl)
43         inc     hl
44         ld      c,(hl)
45         jr      signexte
46
47 ;; Originally from GBDK by Pascal Felber.
48
49 __mulschar_rrx_s::
50         ld      hl,#2+1
51         add     hl,sp
52
53         ld      e,(hl)
54         dec     hl
55         ld      l,(hl)
56
57         ;; Fall through
58 __mulschar_rrx_hds::
59         ;; Need to sign extend before going in.
60         ld      c,l
61
62         ld      a,l
63         rla
64         sbc     a,a
65         ld      b,a
66 signexte:
67         ld      a,e
68         rla
69         sbc     a,a
70         ld      d,a
71
72         jp      __mul16
73