Search code examples
assemblymipsfixed-pointinteger-arithmetic

Fixed point aritmetic in MIPS


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?


Solution

  • 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.