EmbDev.net

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


Author: Ya Ch (Company: frau) (cherry)
Posted on:

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

Author: Jack Braun (jackbraun)
Posted on:

Rate this post
0 useful
not useful

Author: Ya Ch (Company: frau) (cherry)
Posted on:

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

Author: Matthias (Guest)
Posted on:
Attached files:

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.

But I think, it will help you increase it to 32bit.

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...

Author: Ya Ch (Company: frau) (cherry)
Posted on:

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?

Author: Jörg X. (Guest)
Posted on:

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

Author: Christoph Kessler (db1uq) (christoph_kessler)
Posted on:

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&...
about division on AVR

Author: Ya Ch (Company: frau) (cherry)
Posted on:

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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.