2011-07-10 14:51:03 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2011-07-10
|
|
|
|
;
|
|
|
|
; CC65 runtime: 8x16 => 24 unsigned multiplication
|
|
|
|
;
|
|
|
|
|
|
|
|
.export umul8x16r24, umul8x16r24m
|
|
|
|
.export umul8x16r16, umul8x16r16m
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
2019-02-28 16:30:34 +00:00
|
|
|
.macpack cpu
|
2011-07-10 14:51:03 +00:00
|
|
|
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
; 8x16 => 24 unsigned multiplication routine. Because the overhead for a
|
|
|
|
; 8x16 => 16 unsigned multiplication routine is small, we will tag it with
|
2014-05-11 14:43:06 +00:00
|
|
|
; the matching labels, as well.
|
2011-07-10 14:51:03 +00:00
|
|
|
;
|
2014-05-11 14:43:06 +00:00
|
|
|
; routine LHS RHS result result also in
|
2011-07-10 14:51:03 +00:00
|
|
|
; -----------------------------------------------------------------------
|
2014-05-11 14:43:06 +00:00
|
|
|
; umul8x16r24 ax ptr1-low ax:sreg-low ptr1:sreg-low
|
|
|
|
; umul8x16r24m ptr3 ptr1-low ax:sreg-low ptr1:sreg-low
|
2011-07-10 14:51:03 +00:00
|
|
|
;
|
2014-05-11 14:43:06 +00:00
|
|
|
; ptr3 is left intact by the routine.
|
2011-07-10 14:51:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
umul8x16r24:
|
|
|
|
umul8x16r16:
|
|
|
|
sta ptr3
|
|
|
|
stx ptr3+1
|
|
|
|
|
|
|
|
umul8x16r24m:
|
|
|
|
umul8x16r16m:
|
2019-02-28 16:30:34 +00:00
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
|
|
|
stz ptr1+1
|
|
|
|
stz sreg
|
|
|
|
.else
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #0
|
2011-07-10 14:51:03 +00:00
|
|
|
stx ptr1+1
|
2013-05-09 11:56:54 +00:00
|
|
|
stx sreg
|
2019-02-28 16:30:34 +00:00
|
|
|
.endif
|
2011-07-10 14:51:03 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #8 ; Number of bits
|
2011-07-10 14:51:03 +00:00
|
|
|
lda ptr1
|
|
|
|
ror a ; Get next bit into carry
|
|
|
|
@L0: bcc @L1
|
|
|
|
|
|
|
|
clc
|
2020-08-29 14:21:45 +00:00
|
|
|
tax
|
|
|
|
lda ptr3
|
2011-07-10 14:51:03 +00:00
|
|
|
adc ptr1+1
|
|
|
|
sta ptr1+1
|
|
|
|
lda ptr3+1
|
|
|
|
adc sreg
|
|
|
|
sta sreg
|
2020-08-29 14:21:45 +00:00
|
|
|
txa
|
2011-07-10 14:51:03 +00:00
|
|
|
|
|
|
|
@L1: ror sreg
|
2013-05-09 11:56:54 +00:00
|
|
|
ror ptr1+1
|
|
|
|
ror a
|
2011-07-10 14:51:03 +00:00
|
|
|
dey
|
|
|
|
bne @L0
|
|
|
|
|
|
|
|
sta ptr1 ; Save low byte of result
|
|
|
|
ldx ptr1+1 ; Load high byte of result
|
2013-05-09 11:56:54 +00:00
|
|
|
rts ; Done
|
2011-07-10 14:51:03 +00:00
|
|
|
|
|
|
|
|