什么是抵消?

What's an offset?

我一直在 MIPS 指令表中看到偏移字,例如 this one:

+--------------------------------------------------------------+
|                           BEQ                                |
+--------------------------------------------------------------+
| Description:                                                 |
|                                                              |
| Branches if the two registers are equal                      |
+--------------------------------------------------------------+
| Operation:                                                   |
|                                                              |
| if $s == $t advance_pc (offset << 2)); else advance_pc (4);  |
+--------------------------------------------------------------+
| Syntax:                                                      |
|                                                              |
| beq $s, $t, offset                                           |
+--------------------------------------------------------------+
| Encoding:                                                    |
|                                                              |
| 0001 00ss ssst tttt iiii iiii iiii iiii                      |
+--------------------------------------------------------------+

偏移量到底是什么?

偏移量,在拓扑学上是有序集合中的移动向量。偏移量是可定义的,当且仅当存在起始元素时,与您定义移动的起始元素相比。假设你有

的几何点

(x1, ..., xn)

如果需要从这一点着手,那么偏移向量可以定义为

(o1, ..., on)

结果点是:

(x1 + o1, ..., xn + on)

如果您有一个有序列表,那么 o 的数字偏移量会告诉您应该处理的索引。

In computer science, an offset within an array or other data structure object is an integer indicating the distance (displacement) from the beginning of the object up until a given element or point, presumably within the same object. The concept of a distance is valid only if all elements of the object are of the same size (typically given in bytes or words).

取自here。然而,引用有点不准确,因为距离不需要具有相等大小的对象,依赖性是度量空间的存在。此外,引用告诉您,您的代数结构中必须有一个最小的元素,这不完全是依赖关系。更一般地说,您需要有一个明确定义的起点。

在您的特定情况下,offset 是一个数值,以字节为单位,表示从内存中某个位置开始的移动向量。请注意,32 位是四个字节,这就是偏移量为 4 的原因。

还有一个不太数学化的解释:分支是相对于程序计数器的。偏移量表示 "far" 如何从 "current" PC 值(添加到 PC 以到达目的地的偏移量)。在汇编中,偏移量通常由汇编程序计算,因此您只需将目标放在那里