Re: A86: ASM Programming Test - div 3
[Prev][Next][Index][Thread]
Re: A86: ASM Programming Test - div 3
David Phillips wrote:
>
> I spent about a day trying to figure this out. It's not possible. To
> divide by shifting requires at least a 16 or 32 bit fixed-point number, and
> it still comes out a little too bit too small (reference: "More Tricks of
> the Game Programming Gurus"). For example, to divide x by 3 in C (the ">>"
> operator means shift right N places...same as the assembler uses):
>
> x_div_3 = (x >> 2) + (x >> 4) + (x >> 6) + (x >> 8)
Try
> x_div_3 = (x >> 2) + (x >> 4) + (x >> 6) + (x >> 8) + R >> 2
R = (x & 3) + ((x & 15) >> 2), or
R = (x & 3) + ((x & 15) >> 2) + ((x & 63) >> 3), or
R = (x & 3) + ((x & 15) >> 2) + ((x & 63) >> 3) + (x >> 6)
to see if the result gets better.
NSJ aka Viriato
l41324@alfa.ist.utl.pt
nmasj@camoes.rnl.ist.utl.pt
http://camoes.rnl.ist.utl.pt/~nmasj - DemoAdict/TaradoPorDemos
Follow-Ups:
References: