How does an AVR perform floating point Arithmetic

后端 未结 3 1533
失恋的感觉
失恋的感觉 2021-01-01 02:09

I\'m trying to implement a support for double and float and corresponding basic arithmetic on a CPU without an FPU.

I know that it is possi

3条回答
  •  余生分开走
    2021-01-01 02:34

    Avr uses AVR Libc, which you can download and examine.

    There is a math library, but that is not what you are looking for. That contains the standard functions defined in math.h.

    Instead, you need functions that perform multiplication and things like like that. These are also in Libc, under fplib and written in assembly language. But the user doesn't call them directly. Instead, when the compiler comes across a multiplication involving floats, the compiler will choose the correct function to insert.

    You can browse through the AVR fplib to get an idea of what to do, but you are going to have to write your own assembly or bit-twiddling code for your processor.

    You need to find out what standard your processor and language are using for floating point. IEEE, perhaps? And you'll also need to know if the system is little-endian or big-endian.

    I am assuming you system doesn't have a C compiler already. Otherwise, all the floating point operations would already be implemented. That "twice()" function (actually square()) would work just fine as it is.

提交回复
热议问题