Simple FPU Operations
02 Dec 2012The CPU itself is an impressive piece of kit just by itself however it does struggle to do complex floating point mathematics. Chip designers noticed this deficiency pretty quickly and bolted on a floating-point arithmetic unit. It should be noted at this point that many, many other tutorial/article writers have gone into great depth explaining how to program FPU’s and they have been great references to me in previous times:
Anyway, this blog post is just going to show you a few nuggets that you can use straight away. It’s always fun seeing this stuff in action. This snippet will sum (accumulate) together an array of doubles.
This following snippet will show you a simple addition, subtraction, multiplication and division. You’ll notice a pretty distinct pattern in what to do in these situations. It’ll follow:
- Load the first term (
fld
) - Apply the operator (
fadd
,fsub
,fmul
,fdiv
) with the second term - Store the result into memory
With a bit of extra help from the C library, you can print out values that you’re using in the FPU. The following snippet prints PI to the console.
As I find other snippets in old pieces of code, I’ll be sure to add them to this page.