32 bit/32 bit division by using atmega128

OP (Company: frau) #582098
Rate this post
• ▲ 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
Guest #582106
Rate this post
• ▲ 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...
Attached files:
Guest #582244
Rate this post
• ▲ 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

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.