i need to divide one register with another

but i can not fibd the divide command in the avr's instruction set

can anyone help me to solve this problems

thank u

## need a divider command

the AVR does not have a divide instruction. You will have to perform the division in software. Check out Atmels appnote AVR200 for code examples on how to do division in software.

Go to this link.

http://www.atmel.com/dyn/resources/prod_documents/DOC0936.PDF

Expanding on what Steve said: multiply by reciprocal is very fast when the divisor is constant (and shifting won't suffice). Even with today's desktop CPUs, division is still slow (4 times slower than multiplication on the Pentium family, IA64, and AMD64), though it's faster on some chips.

For example:

result = n / 10; result = (n * 0x1A) >> 8; //same result in assembler, its even simpler: ; to divide r16 by 10: ldi r17, $1A mul r16, r17 ; r1 is the result (no shift required; ignore low byte in r0)

The trick is getting the right constant to multiply by. There are free utilities out there for this, I sometimes use a free utility from AMD to do this, but there's yet another way. Take any modern optimising compiler (gcc, MSVC, etc.), and compile a quick main() that divides a number by a constant. Read the assembler output, and you'll see the required value.

Cheers

i am using avrstudio now

and already read those aplication note but still doesnt understand the algorhtym.

can any one help me giving the simplier code to perfome a divide

thanks a lot guys

Actually, it's the same as you learned in 4th grade, except in base 2 instead of base 10.

I just used the code straight out of the app note. Divides nicely.

You don't need a computer science degree to learn binary math. The internet is full of information if you look. :oops:

Here's two links to get you started.

http://home.carolina.rr.com/bigbare/Index.html

http://courses.cs.vt.edu/~cs1104/BuildingBlocks/divide.030.html

Spend a little time comparing the app notes information with the information in these links. Then write a small routine and do some simulations. Once you learn the basics, then you will be able to adapt these to perform larger and more complex operations.

thanks a lot for the information

already can figure out how to do this