[A83] Re: Faster Multiplication


[Prev][Next][Index][Thread]

[A83] Re: Faster Multiplication



That wouldn't be very fast for large values of c and e.  Is there any reason 
not to use this?

mult:    ;hl = e * h
 ld l,0
 ld d,l
 ld b,8
multloop:
 add hl,hl
 jr nc,$+3
 add hl,de
 djnz multloop
 ret

And you could always unroll the loop to gain a bit of speed...

mult:    ;hl = e * h
 ld l,0
 ld d,l
 add hl,hl           ;1
 jr nc,$+3
 add hl,de
 add hl,hl           ;2
 jr nc,$+3
 add hl,de
 add hl,hl           ;3
 jr nc,$+3
 add hl,de
 add hl,hl           ;4
 jr nc,$+3
 add hl,de
 add hl,hl           ;5
 jr nc,$+3
 add hl,de
 add hl,hl           ;6
 jr nc,$+3
 add hl,de
 add hl,hl           ;7
 jr nc,$+3
 add hl,de
 add hl,hl           ;8
 ret nc
 add hl,de
 ret


In a message dated 5/30/2001 3:23:44 PM Eastern Daylight Time, 
tijl.coosemans@mail.be writes:


> ;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!
> :MulCode1
>     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 MulCode1
> 
> 
> just 3 bytes smaller...
> 




----
Jonah Cohen
<ComAsYuAre@aol.com>
http://jonah.ticalc.org