Re: A85: Fast 8 bit multiply routine
[Prev][Next][Index][Thread]
Re: A85: Fast 8 bit multiply routine
Wouldn't that routine be really slow when the number in b grows large?
-mike pearce
On Mon, 18 Aug 1997 17:08:08 -0700, you wrote:
>Michael Pearce wrote:
>>
>> Does any one have a good (fast) routine to multiply 2, 8 bit numbers
>> together?
>>
>> -mike pearceDepends on your situation. Here are some common solutions:
>
> ld b,1st number
> ld e,2nd number
> ld d,0
> ld hl,0
>Loop:
> add hl,de
> djnz Loop
>
>The result is a 16 bit number in hl. By the way, if b=0 then hl=256*e, if e=0
>then hl=0. If the result will always be <256 then this should be faster
>
> ld b,1st number
> ld e,2nd number
> xor a ;ld a,0
>Loop:
> add a,e
> djnz Loop
>
>Same traps. If you want to multiply by 2^x, do this:
>
> ld b,x
> ld l,first number
> ld h,0
>Loop:
> add hl,hl
> djnz Loop
>
>Those routines may not be the fastest but should give you some ideas.
>
>--
>Terry Peng
>email- tpeng@geocities.com
>web- http://www.geocities.com/SiliconValley/Bay/5104/index.html
>
Follow-Ups:
References: