Re: A86: ASM Programming Test


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

Re: A86: ASM Programming Test




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)

I ended up using a little subtraction loop to divide a number (code cut from
program):

 ld a,(MapY)    ; load y coord
 ld b,3      ; need to divide by 3
 ld c,0      ; it starts at 1, always add once
DoRadarL:
 inc c      ; increase quotient
 sub b      ; subtract divisor
 jr nc,DoRadarL    ; loop until it's negative

The dividend is in A, the divisor in B and C is the quotient.  It just
increments the quotient and decrements the dividend by the divisor until the
dividend is less than 0.  If you add the divisor to the dividend at the end,
then you will have the remainder as well.

-----Original Message-----
From: Dux Gregis <assets@eden.rutgers.edu>
To: assembly-86@lists.ticalc.org <assembly-86@lists.ticalc.org>
Date: Wednesday, December 02, 1998 3:26 PM
Subject: Re: A86: ASM Programming Test


>
>How about for the challenge write a call that divides the accumulator by 3?


Follow-Ups: