]> git.sur5r.net Git - cc65/blob - libsrc/runtime/imul16x16r32.s
Added division routine. Removed C callable entry points from mul routines,
[cc65] / libsrc / runtime / imul16x16r32.s
1 ;
2 ; Ullrich von Bassewitz, 2010-11-03
3 ;
4 ; CC65 runtime: 16x16 => 32 signed multiplication
5 ;
6
7         .export         imul16x16r32
8         .import         negax, umul16x16r32m, negeax
9         .importzp       ptr1, ptr3, tmp1
10
11
12 ;---------------------------------------------------------------------------
13 ; 16x16 => 32 signed multiplication routine.
14 ;
15 ;   lhs         rhs           result          result also in
16 ; -------------------------------------------------------------
17 ;   ptr1        ax            ax:sreg
18 ;
19 ; There is probably a faster way to do this.
20 ;
21
22 imul16x16r32:
23         stx     tmp1
24         cpx     #0
25         bpl     @L1
26         jsr     negax
27 @L1:    sta     ptr3
28         stx     ptr3+1
29
30         lda     ptr1+1
31         eor     tmp1
32         sta     tmp1
33         lda     ptr1
34         ldx     ptr1+1
35         bpl     @L2
36         jsr     negax
37         sta     ptr1
38         stx     ptr1+1
39 @L2:    jsr     umul16x16r32m
40         ldy     tmp1
41         bpl     @L3
42         jmp     negeax
43 @L3:    rts
44