]> git.sur5r.net Git - cc65/blob - libsrc/runtime/umul8x16r24.s
ff7d0bae6f07ffdc27054676f2e405e0d9da1315
[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
13 ;---------------------------------------------------------------------------
14 ; 8x16 => 24 unsigned multiplication routine. Because the overhead for a
15 ; 8x16 => 16 unsigned multiplication routine is small, we will tag it with
16 ; the matching labels, as well.
17 ;
18 ;  routine         LHS         RHS        result          result also in
19 ; -----------------------------------------------------------------------
20 ;  umul8x16r24     ax          ptr1-low   ax:sreg-low     ptr1:sreg-low
21 ;  umul8x16r24m    ptr3        ptr1-low   ax:sreg-low     ptr1:sreg-low
22 ;
23 ; ptr3 is left intact by the routine.
24 ;
25
26 umul8x16r24:
27 umul8x16r16:
28         sta     ptr3
29         stx     ptr3+1
30
31 umul8x16r24m:
32 umul8x16r16m:
33         ldx     #0
34         stx     ptr1+1
35         stx     sreg
36
37         ldy     #8              ; Number of bits
38         ldx     ptr3            ; Get into register for speed
39         lda     ptr1
40         ror     a               ; Get next bit into carry
41 @L0:    bcc     @L1
42
43         clc
44         pha
45         txa
46         adc     ptr1+1
47         sta     ptr1+1
48         lda     ptr3+1
49         adc     sreg
50         sta     sreg
51         pla
52
53 @L1:    ror     sreg
54         ror     ptr1+1
55         ror     a
56         dey
57         bne     @L0
58
59         sta     ptr1            ; Save low byte of result
60         ldx     ptr1+1          ; Load high byte of result
61         rts                     ; Done
62
63