Re: A82: fast multiply...
[Prev][Next][Index][Thread]
Re: A82: fast multiply...
At 12:02 1997-08-03 +0200, you wrote:
> This is directly from "Programming the Z80" by Rodney Zaks. It's very
>optimized, but it could be unrolled to further speed it up.
> ;HL=L*E
> ld B, 8
> MULT:
> add HL, HL
> jr nc, NOADD
> add HL, DE
> NOADD:
> djnz MULT
>
>On Sat, 3 Aug 1996, Lars Ahlzén wrote:
>
>> Hello!
>> As the Z80 doesn't have a multiply instruction (which is almost
>> necessary for star-scrolls and things like that) then I've tried to do
>> my own routines. It surely works, but I think it takes more than 80
>> cycles to execute. (here's the code:)
>>
>> Multiply:
>> ; Multiplies b and de and gives the product in hl
>> ld hl,0
>> ld a,1
>> mulloop:
>> ld c,a
>> and b
>> jr z,noadd
>> add hl,de
>> noadd:
>> ld a,c
>> sla e
>> rl d
>> add a,a
>> jr nc,mulloop
>> ret
>>
>> Someone must have written a faster way of mulitplying two 8-bit numbers
>> than this, or...? If so, could you reply to this and show your routines?
>>
>> (by the way: is there a fast way for integer division, too?)
>>
>> Lars Ahlzen
>> lars.ahlzen@swipnet.se
>>
>
>--------------------------------------------------
>Henrik Edlund Piett Productions
>piett@piett.com http://www.piett.com/
>
> "They were in the wrong place at the wrong time.
>Naturally they became heroes."
> Leia Organa of Alderaan, Senator
>--------------------------------------------------
Thanks a lot for the code! That piece should be a lot faster than mine!
//Lars
Follow-Ups: