>>
>>
>> Hello...
>>
>> For those who wanted or needed them...
>> Here are the math-routines (somebody asked me for them; who?)
>> Let's have a math-routines-as-fast-as-possible-competion!
>>
>> . ; function: 16 bits multiply routine; N.O.P.; [EMAIL PROTECTED]
>> . ;entry name: Mul16Bits
>> . ; in: DE, BC
>> . ; out: HL=DE*BC
>> . ; changes: A=0, HL, DE=0, flags
>> . ; speed: 1089 clocks (3287 calculations/sec)
>>
>>
Ok.
Here are some routines I wrote a few years ago. I never measured/calculated
their
speed. I have included three source files which I will also put on my
home-page
(http://www.inter.nl.net/users/A.P.Wulms/Html/main_index.html) and/or on
ftp.funet.fi
in the msx section.
The first routine calculates : DE=D*E
The second routine calculates: HL:AC=DE*BC
The third routine actually is no routine but it is a bunch of macro's for
gen80
to use the R800 multiply instructions.
Best regards,
Alex Wulms
--START OF FILE1: MUL16B.GEN
; ***************************************
; * Multiply D with E and return a 16-bit result
; * Written by XelaSoft. May be used by anyone.
; * in: D,E : the factors
; * out: DE,A: result, DE = 16-bit result, A = MSB of result
; * B = 0
; * changes: F
; ***************************************
mul16b: xor a
ld b,8
mul16b2: rr e
jr nc,$+3 ; not 1 => do not add
add a,d
rra ; shift result lsb into C-flag
djnz mul16b2
rr e ; C-flg can be placed in lsb
ld d,a
ret
--END OF FILE1: MUL16B.GEN
--START OF FILE2: MUL32B.GEN
; ***************************************
; * Multiply DE with BC and return a 32-bit result
; * Written by XelaSoft. May be used by anyone.
; * in: DE,BC: the factors
; * out: HL:AC: result HL = MSB, AC = LSB
; * changes: B,AF
; ***************************************
mul32b: ld a,b
ld b,16 ; 16 bits to process
ld hl,0
or a ; reset carry
mul32b2: rra
rr c ; check bit 0 of AC
jr nc,mul32b3 ; 0 ==> do not add
add hl,de ; add it
mul32b3: rr h ; Cf of addition is needed to
rr l
djnz mul32b2 ; process next bit and put Cf in AC
rra ; finish the job
rr c
ret
--END OF FILE2: MUL32B.GEN
--START OF FILE3: MUL2.MAC
..comment \
Multiply macro's, version 2.0, (C) 1993-1996 by XelaSoft
Released into public domain by XelaSoft, 8-3-1993
Translated this comment into English and re-released: 31-8-1996
A. Wulms
Oude Singel 206
2312 RJ Leiden
[EMAIL PROTECTED]
2 macro's to use the R800 multiply instructions with gen80.
Usage:
mulub Register ; 8 bits unsigned multiply
==> HL := A * Register. Register can only be B,C,D or E (case
insensitive)
muluw RegPair ; 16 bits unsigned multiply
==> DE:HL := HL * RegPair. RegPair may only be BC or SP (case
insensitive)
Ps: This macro uses a number of constants with the following form:
rmb_X or rmw_XY
where X or XY is a register/register pair
\
rmb_b: equ 0 .shl. 3
rmb_B: equ rmb_b
rmb_c: equ 1 .shl. 3
rmb_C: equ rmb_c
rmb_d: equ 2 .shl. 3
rmb_D: equ rmb_d
rmb_e: equ 3 .shl. 3
rmb_E: equ rmb_e
rmw_bc: equ 0 .shl. 3
rmw_bC: equ rmw_bc
rmw_Bc: equ rmw_bc
rmw_BC: equ rmw_bc
rmw_sp: equ %110 .shl. 3
rmw_sP: equ rmw_sp
rmw_Sp: equ rmw_sp
rmw_SP: equ rmw_sp
mulub: macro @r
db #ed, %11000001 .or. rmb_@r
endm
muluw: macro @r
db #ed, %11000011 .or. rmw_@r
endm
--END OF FILE3: MUL2.MAC