在RVDS下使用Cortex-M0进行整数除法 [英] Integer division with Cortex-M0 under RVDS
问题描述
我正在尝试将64位整数类型划分为32位整数类型,并且我将RVDS 4.1用作工具链.
I am trying to divide a 64 bits integral type to a 32 bits one, and I am using RVDS 4.1 as a tool-chain.
Cortex-M0没有硬件除数,所以我可以做下面的操作吗?如果可以,怎么办?
Cortex-M0 does not have hardware divisor, so can I do the operation below? If so How?
unsigned long int b = 2590202;
unsigned long long int a = 953502716552001ULL;
unsigned long long int result;
result = a/b;
推荐答案
编译器将编译除法运算,作为对执行软件64位除法算法的库子例程的调用.您可能还必须告诉编译器与数学库链接,我没有专门使用RVDS的经验.
The compiler will compile the division operation as a call to a library subroutine that performs a software 64-bit division algorithm. You might have to also tell the compiler to link with the math library, I have no experience with RVDS specifically.
为什么不尝试自己编译代码,看看会发生什么?尝试反汇编生成的机器代码,以查看其工作方式:这应该很有教育意义.
Why not try compiling the code yourself and see what happens? Try disassembling the resulting machine code to see how it works: it should be very educational.
这篇关于在RVDS下使用Cortex-M0进行整数除法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!