[A83] Faster Multiplication
[Prev][Next][Index][Thread]
[A83] Faster Multiplication
Ok, i just finished up a multiplication function, it is about 7 bytes longer
then most, 13 cycles, under certain circumstances, slower, but at other
times, it can get incredibly faster.
for example: if you were to do 0*64, my function would take 75 cycles to
stop, while the other would take 6k or so cycles to be done
the general rule for when this is faster, is when the 2nd number is 2 larger
then the 1st number.
I'll include it below. Tell me what you think.
Oh, and if you have any suggestions, other then using this function is slower
then doing add hl,hl etc... for multiplying by 2, or what ever, your right,
this is slower, but for multiplying two unknowns, this should be helpfull...i
think, email it to me, I would like too see how much faster i can get this.
;quick multiply
;Input: C and E
;Output: Hl = C*E
mult:
xor a ;flush a
ld h,a ;flush hl and d
ld l,a
ld d,a
ld a,c ;save c to a to check...
cp e ;here we check too see which one is bigger, c or e
jp c,mulswitch ;if c is smaller then e, switch them!
xor a ;reset a
cp c ;and the check for 0
:MulCode ;normal multiplication code...
ret z
add hl,de
dec c
jp MulCode
:mulswitch ;switch c and e, then run the main code
ld a,c
ld c,e
ld e,a
ld a,0
cp c
jp MulCode