# Forum: µC & Digital Electronics 32 bit/32 bit division by using atmega128

Rate this post
 0 ▲ useful ▼ not useful
Hi all,

Firstly sorry for the English post here, though I'm a student in Germany
but my German is really limited, by which I cant express myself. However
I know this is a hot forum, and I am wondering if someone can help me a
bit.

I am using mega128 to do an embedded control application, in a step I
need to do a 32bit/32bit division. This is a bit tough for me because I
am using assembly language and mega128 doesnt have division instruction.
I searched a lot on the internet but still being confusion.

Could anyone show me a sample code or a division algorithm on how to do
it? Really appreciate that.

Tudou

Rate this post
 0 ▲ useful ▼ not useful
http://www.mikrocontroller.net/articles/AVR-Tutorial:_Arithmetik

Rate this post
 0 ▲ useful ▼ not useful
oh, that's really fast, thanks a lot!

Rate this post
 0 ▲ useful ▼ not useful
some years ago, I had a similar problem. At this time, I wrote some
subroutines for multiply and divide, by only in 16bit.

The underlaying idea is the same, like you calculate this on papier,
like in the first years of school:
example:
nbr#1        nbr#2
0100'1010 : 0001'0010
shift nbr#2 one cycle LESS than  nbr#1<nbr2:
0100'1010 (nbr#1)
0100#1000 (nbr#2*)
subract:        ----------------------
.....
shift right...

Rate this post
 0 ▲ useful ▼ not useful
thanks, but 32bit/32bit algorithm is only available when the dividend is
bigger than the divisor, right? what if my dividend is smaller than
divisor, I tried, and everytime I got 0.

Any idea?

Rate this post
 0 ▲ useful ▼ not useful
Of course it is, Integer-Divison  is (almost) always rounded downwards -
and the next whole number smaller than 1 is 0 -- there are no ints
between them ;)
You could use some kind of fix-point arithmetics, where the LSB
represents i.e. 1/256 (or 0.001, or ...) rather than 1. But in that case
you have to take care that your program can cope with that (put the "."
in outputs and things alike) or you google for a Floating-point Library
( but that sounds like an assembler-nightmare to me).

sry, my (written) english is a little rusty ;)

hth. Jörg

Rate this post
 0 ▲ useful ▼ not useful
here are "DIRTY DAN"s MATH TRICKS", also called "RetroDan":
http://8515.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=50912&view=next
about division on AVR

Rate this post
 0 ▲ useful ▼ not useful
thank you so much for the information

• $formula (LaTeX syntax)$