Re: A86: Re: new ideas...


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

Re: A86: Re: new ideas...




Except that what you did just rotates the bits, so it's not *7. You need to
use add a,a to multiply.

Is it /really/ necessary to list all of these out? Here's the basic
procedure:
[A] pick a number to multiply by
[B] divide that number by two integer division repeatedly (see below)
[C] keep doing ADD A,A and keep track of the current multiplication. if you
come close to a factor that you found above (reverse order), subtract or add
(as necessary) to get to that factor, then keep doing ADD A,A

Example:
[A] we pick 21
[B] 21 / 2 = 10 r 1; 10 / 2 = 5 r 0; 5 / 2 = 2 r 1; 2 / 2 = 1 r 0
[C] LD B,A
    ADD A,A ;*2 - R0
    ADD A,A ;*4 - R1, so add B
    ADD A,B ;*5 - ok
    ADD A,A ;*10 - R0
    ADD A,A ;*20 - R1, so add B
    ADD A,B ;*21

This is not always optimal; sometimes you will want to SUB B instead and you
need to use a different algo. If there are enough different numbers that you
want to multiply by, a generic mult routine is much more advisable. Jimmy &
I came up with one that's around 100 t-states I think...

> >;multiply n by 7
> >ld a, 2 ;n=2
> >ld b, a ;store value of n
> >rla ;n*2
> >rla ;n*4
> >rla ;n*8
> >sub b ;(n*8-n) or n*7
> >;a now holds result of n times 7. n=2, so value in A is 14.




Follow-Ups: References: