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

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now