MIPS 中的定点运算

Fixed point aritmetic in MIPS

我需要在 MIPS 汇编中实现一些代码,特别是使用定点运算。我错过了什么或者那里没有这样的东西吗?如果它不是 MIPS 的一部分,我如何使用整数实现定点,即 add/sub/mul/div?

MIPS 是 32 位,您可以按照自己的意愿排列 with 和数字的小数部分 fixed<w,b> 。可以隐式调整二进制小数点。 addsub 使用简单的数学运算,对于 mul/div 可以使用指令 sllsrl.

这里有个link解释的很好。

http://www-inst.eecs.berkeley.edu/~cs61c/sp06/handout/fixedpt.html

要实现定点运算代码,您只需要处理器支持整数运算。当然有些处理器可能有一些优化定点代码的指令,但这不是强制性的。

对于任何定点代码,您首先需要确定表示数字的整数和小数部分所需的位数,然后您将使用普通指令进行加减乘和运算除以执行定点运算。

在这篇关于 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 的维基百科文章中。