Charles, Actually, I was replying to a question, not making it. However, in response to what you say, with which I agree in general situations, for this particular example of multiplying by a known fixed constant (5/1000000), I think by using the FDIV instruction, it's possible to divide two 16-bit numbers where the numerator is less than the denominator. So, if one manages to simplify the problem and make both the numerator and the denominator small enough to fit in 16-bits (e.g., by factoring which turns 5/1000000 to 1/(2^6 x 5^5) thus reducing the whole problem to a a couple of divisions, then depending on the relationship between numerator and denominator, use either the IDIV or FDIV (in this case FDIV). I quote from the FDIV description in the HC11 reference manual: "FDIV is equivalent to multiplying the numerator by 2^16 and then performing a 32-bit by 16-bit integer divide. The result is interpreted as a binary-weighted fraction, which resulted from the division of a 16-bit integer by a larger 16-bit integer. A result of $0001 corresponds to 0.000015, and $FFFF corresponds to 0.99998. The remainder of an IDIV instruction can be resolved into a binary-weighted fraction by an FDIV instruction. The remainder of an FDIV instruction can be resolved into the next 16 bits of binary-weighted fraction by another FDIV instruction." Since after the 2^6 division (a shift right six times) the result can never be greater than 2^10 (1024), and the second divisor is the constant 5^5 (3125), we have the dividend always being larger than the divisor and, therefore, an FDIV could be used to get a good result. Some accuracy may be lost because of the initial right shifting which discarted some bits, but I think it's not too significant. If such shortcuts aren't possible, one must use a floating point package to carry out this operation, as the hardware is incapable of directly providing a result. ----- Original Message ----- From: Melear Charles-rdph40 <> To: <> Sent: Wednesday, April 16, 2003 12:31 AM Subject: RE: [m68HC11] REALLY NEED HELP TO DO DIVISION in assembly > Tony, > > As you have probably gathered from all the traffic on your question about division, the bottom line is that you just can't effectively use the divide instructions when your denominator is very large and your numerator very small. > > Your best bet (I think) is to shift the numerator to the left several times and then do the division. > > When you get the result, you will have to remember what you did, that is, how many times did you shift to the left. Well, once you get an answer, you will have to shift to the right by the same number of times. This will take all the significant digits off the right hand end of your result and you will be right back where you started. > > What I think you are going to have to do is make up your own format to save the results in a 32 bit or a 64 bit format. This will have to be some type of "do your own thing". > > You may have to do two divisions. Do the original divide and then take the remainder and divide it by the original denominator. Then you will have to deal with the "upper half" of the result and the "lower half" of the result. > > I believe that you are just going to have to make up your own way to store 64 bit results. > > Regards, > > Charlie > > -----Original Message----- > From: Tony Papadimitriou [mailto:] > Sent: Tuesday, April 15, 2003 8:43 AM > To: > Subject: Re: [m68HC11] REALLY NEED HELP TO DO DIVISION in assembly > By the way, an example of FDIV use is found in this program (in > French): > > http://martial.benoit.free.fr/files/weller.txt > > Look at the routine ADC_2_DEGREE to get an idea. > > ----- Original Message ----- > From: Tony Papadimitriou <> > To: <> > Sent: Tuesday, April 15, 2003 4:23 PM > Subject: Re: [m68HC11] REALLY NEED HELP TO DO DIVISION in assembly > > 5/1000000 = 1/(2^6 x 5^5) > > > > So, shift right six times, then divide the result by 5^5 or 3125. > > > > If you need help with the actual division process, search the > > Internet, the HC11 WebRing, or Mot's web site for sample code to do > > division. > > > > |