]> git.sur5r.net Git - cc65/blob - libsrc/runtime/umul8x16r24.s
Fixed _textcolor definition.
[cc65] / libsrc / runtime / umul8x16r24.s
1 ;
2 ; Ullrich von Bassewitz, 2011-07-10
3 ;
4 ; CC65 runtime: 8x16 => 24 unsigned multiplication
5 ;
6
7         .export         umul8x16r24, umul8x16r24m
8         .export         umul8x16r16, umul8x16r16m
9
10         .include        "zeropage.inc"
11
12         .macpack        cpu
13
14 ;---------------------------------------------------------------------------
15 ; 8x16 => 24 unsigned multiplication routine. Because the overhead for a
16 ; 8x16 => 16 unsigned multiplication routine is small, we will tag it with
17 ; the matching labels, as well.
18 ;
19 ;  routine         LHS         RHS        result          result also in
20 ; -----------------------------------------------------------------------
21 ;  umul8x16r24     ax          ptr1-low   ax:sreg-low     ptr1:sreg-low
22 ;  umul8x16r24m    ptr3        ptr1-low   ax:sreg-low     ptr1:sreg-low
23 ;
24 ; ptr3 is left intact by the routine.
25 ;
26
27 umul8x16r24:
28 umul8x16r16:
29         sta     ptr3
30         stx     ptr3+1
31
32 umul8x16r24m:
33 umul8x16r16m:
34 .if (.cpu .bitand ::CPU_ISET_65SC02)
35         stz     ptr1+1
36         stz     sreg
37 .else
38         ldx     #0
39         stx     ptr1+1
40         stx     sreg
41 .endif
42
43         ldy     #8              ; Number of bits
44         ldx     ptr3            ; Get into register for speed
45         lda     ptr1
46         ror     a               ; Get next bit into carry
47 @L0:    bcc     @L1
48
49         clc
50         pha
51         txa
52         adc     ptr1+1
53         sta     ptr1+1
54         lda     ptr3+1
55         adc     sreg
56         sta     sreg
57         pla
58
59 @L1:    ror     sreg
60         ror     ptr1+1
61         ror     a
62         dey
63         bne     @L0
64
65         sta     ptr1            ; Save low byte of result
66         ldx     ptr1+1          ; Load high byte of result
67         rts                     ; Done
68
69