Reputation: 5078
I need to implement some code in MIPS assembly, in particular using fixed point arithmetic. Did I miss something or there is no such thing there? If its not part of MIPS, how can I implement fixed point using integers, that is add/sub/mul/div?
Upvotes: 0
Views: 1277
Reputation: 846
MIPS are 32 bits you can arrange the with
and fractional part of the numbers how you wish fixed<w,b>
. one can implicitly adjust the binary point. The add
and sub
use simple math, for the mul/div
one can use the instruction sll
and srl
.
Here is a link that explain it well.
http://www-inst.eecs.berkeley.edu/~cs61c/sp06/handout/fixedpt.html
Upvotes: 1
Reputation: 570
To implement a fixed point arithmetic code you only need the processor to support integer arithmetic. Of course some processors may have some instructions that optimize fixed point code but it's not mandatory.
For any fixed point code, you need first to determine the number of bits that you need to represent the integer and fraction parts of the number, then you will use the ordinary instructions that do the addition, subtraction, multiplication and dividing to perform your fixed point operations.
In this Wikipedia article about the Q format you will find the concept of Q notation and how to do the basic fixed point operations based on this concept. The code examples in this article is written in C, but you can do the same with the MIPS basic arithmetic instructions.
Upvotes: 2