divMod Function
-
- Posts: 20
- Joined: Mon May 23, 2011 7:41 pm
divMod Function
I'm writing an OS and I need to perform the modulo operand, '%'.
The ARM architecture does not have hardware support for division, so I'll have to write my own function. Any ideas on how to do this?
The ARM architecture does not have hardware support for division, so I'll have to write my own function. Any ideas on how to do this?
-
- Member
- Posts: 141
- Joined: Thu Jun 17, 2010 2:36 am
Re: divMod Function
I'll do the work you should have done (Google)...
Simple\With Code:
http://www.virag.si/2010/02/simple-divi ... assembler/
Best:
http://gmplib.org/~tege/divcnst-pldi94.pdf
You could also compile a simple C program that uses modulo using GCC and look at the assembly.
Simple\With Code:
http://www.virag.si/2010/02/simple-divi ... assembler/
Best:
http://gmplib.org/~tege/divcnst-pldi94.pdf
You could also compile a simple C program that uses modulo using GCC and look at the assembly.
-
- Posts: 20
- Joined: Mon May 23, 2011 7:41 pm
Re: divMod Function
Thank you. I should have specified that I need to write a function in C, which is a bit harder.
-
- Member
- Posts: 141
- Joined: Thu Jun 17, 2010 2:36 am
Re: divMod Function
Why do you need to write a function? Just use the % operator and your compiler will generate the code for you....SonyQrio wrote:Thank you. I should have specified that I need to write a function in C, which is a bit harder.
-
- Posts: 20
- Joined: Mon May 23, 2011 7:41 pm
Re: divMod Function
SonyQrio wrote:The ARM architecture does not have hardware support for division...
Re: divMod Function
What about this....
I haven't tested it but it might work.
Code: Select all
int mod_func(int num, int den) {
return num % den;
}
If a trainstation is where trains stop, what is a workstation ?
-
- Member
- Posts: 141
- Joined: Thu Jun 17, 2010 2:36 am
Re: divMod Function
SonyQrio wrote:SonyQrio wrote:The ARM architecture does not have hardware support for division...
Rudster816 wrote: Why do you need to write a function? Just use the % operator and your compiler will generate the code for you....
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: divMod Function
And if it doesn't generate code directly, it'll inject a call to libgcc. Conveniently enough, the source code for libgcc is available (you can use libgcc's code for other things too, such as finding out how to do things like atomic operations).
All else aside, what you need to do here is determine an algorithm for calculating the modulus, and then implement that algorithm.
Your most basic implementation might just involve subtraction and nothing else.
All else aside, what you need to do here is determine an algorithm for calculating the modulus, and then implement that algorithm.
Your most basic implementation might just involve subtraction and nothing else.
-
- Member
- Posts: 595
- Joined: Mon Jul 05, 2010 4:15 pm
Re: divMod Function
GCC generates modulo and division code automatically. If you don't want that, you can search the linux source code which has ARM division example in assembly language.