Jump to content
  • 0

How do I understand divide two 16 bits number in 8051 microcontroller?


Danellee

Question

Hi all,
I have this project to code in 8051 series, DS80C320-ECG (data source as reference): "Division of two 16 bit unsigned integers being in the internal memory, quotient and remainder should be stored".
I find a way to do it but there is a part of the program that i don't understand, I attach it.
I've noted which part i don't understand. By "don't understand", means that i'm not understanding why do we have to do all those calculations to find the quotient and the remainder.

Is there anyone have ideas of it? Thanks in advance.

DS80C320-ECG Image.jpg

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Division has always been complicated to do in logic. Those old assembler level routines to do coarse integer estimation can be good tutorials in basic math algorithms. ADI has some good literature available for its DSP devices that make for interesting reading. There are also good texts available for a variety of algorithmic computation techniques.

Rarely, do people decide that they need to implement division in hardware. Since the result is rarely an integer, you need to handle fixed point, floating point, or block floating point number formats. Even in the early days of microprocessor based designs people rarely found the effort worthwhile.

If you can work it out so that the division problem is x/n where n is known and fixed and x is a variable, then replacing that with x * m, where m=1/n is a much faster and simpler way to go. It's surprising how often you can arrange your design to do that. You can also convert your numbers to log(x) in a convenient base and do log(x)-log(y). For both approaches you need to select a number format and understand how to keep track of the decimal point. Unfortunately, the log(x) algorithm is also a bit complicated and time consuming. You can speed the calculation up with pipelining. The consequence of pipelining is that to get one result incurs a delay or latency proportional to the number of pipe stages. If your are pushing lots of numbers through the pipe then, after the latency to get the first value out you get a new value every clock period, so it generally makes sense when you want to process a lot of data at a time.

Any time you are working with non-integer values there are lots of subtle details, like rounding and truncation effects, to keep track of to avoid errors.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...