2009-08-17 20:48:28 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2009-08-17
|
|
|
|
;
|
|
|
|
; CC65 runtime: multiplication for ints. Short versions.
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export tosumula0, tosmula0
|
2009-08-17 20:48:28 +00:00
|
|
|
.export mul8x16, mul8x16a
|
2013-05-09 11:56:54 +00:00
|
|
|
.import popsreg
|
|
|
|
.importzp sreg, ptr4
|
2009-08-17 20:48:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
; 8x16 routine with external entry points used by the 16x16 routine in mul.s
|
|
|
|
|
|
|
|
tosmula0:
|
|
|
|
tosumula0:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr4
|
|
|
|
mul8x16:jsr popsreg ; Get left operand
|
2009-08-17 20:48:28 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0 ; Clear byte 1
|
|
|
|
ldy #8 ; Number of bits
|
|
|
|
ldx sreg+1 ; Get into register for speed
|
2009-08-17 20:48:28 +00:00
|
|
|
beq mul8x8 ; Do 8x8 multiplication if high byte zero
|
|
|
|
mul8x16a:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr4+1 ; Clear byte 2
|
2009-08-17 20:48:28 +00:00
|
|
|
|
|
|
|
lsr ptr4 ; Get first bit into carry
|
|
|
|
@L0: bcc @L1
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
clc
|
|
|
|
adc sreg
|
|
|
|
pha
|
|
|
|
txa ; hi byte of left op
|
|
|
|
adc ptr4+1
|
|
|
|
sta ptr4+1
|
|
|
|
pla
|
|
|
|
|
|
|
|
@L1: ror ptr4+1
|
|
|
|
ror a
|
|
|
|
ror ptr4
|
2009-08-17 20:48:28 +00:00
|
|
|
dey
|
|
|
|
bne @L0
|
|
|
|
tax
|
|
|
|
lda ptr4 ; Load the result
|
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
; 8x8 multiplication routine
|
|
|
|
|
|
|
|
mul8x8:
|
|
|
|
lsr ptr4 ; Get first bit into carry
|
|
|
|
@L0: bcc @L1
|
|
|
|
clc
|
|
|
|
adc sreg
|
|
|
|
@L1: ror
|
|
|
|
ror ptr4
|
|
|
|
dey
|
|
|
|
bne @L0
|
|
|
|
tax
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr4 ; Load the result
|
|
|
|
rts ; Done
|
2009-08-17 20:48:28 +00:00
|
|
|
|