gpt4 book ai didi

assembly - 如果没有比较指令,不相等如何分支?

转载 作者:行者123 更新时间:2023-12-04 00:29:58 25 4
gpt4 key购买 nike

.text:91C034B4                 li        r11, 0x1E     # Load Immediate
.text:91C034B8 divw r11, r27, r11 # Divide Word
.text:91C034BC mulli r11, r11, 0x1E # Multiply Low Immediate
.text:91C034C0 subf. r11, r11, r27 # Subtract from
.text:91C034C4 bne loc_91C034E0

通常在 PowerPC 中,bne(如果不相等则转移)指令之前有一个比较指令。有人可以解释一下这是如何比较的或者上面的说明中发生了什么吗?

最佳答案

Power 上的 BNE 指令,与许多具有类似分支指令的指令集一样,实际上不需要比较功能。上电时,这条指令只是检查条件寄存器 (CR) 中的位,测试某些位是已设置还是已清除。

在您提供的情况下,subf 的结果将根据结果修改 CR 寄存器。程序员依靠这个减法的副作用来执行测试。

事实上,这通常等同于实际的比较指令,因为比较通常会执行减法以确定要在 CR 中设置哪些位。程序员只是同时做两件事。

我建议您看一下 PowerPC User Instruction Architecture 中的第 2 章引用,其中涵盖了分支处理器。请特别注意第 2.3.1 节:

For Compare instructions, a specified CR field is set to reflect the result of the comparison. The bits of the specified CR field are interpreted as follows. A complete description of how the bits are set is given in the instruction descriptions in Section 3.3.9, “Fixed- Point Compare Instructions” on page 58 and Section 4.6.7, “Floating-Point Compare Instructions” on page 113.

Bit Description:

0- Less Than, Floating-Point Less Than (LT, FL) For fixed-point Compare instructions, (RA) < SI or (RB) (signed comparison) or (RA)

1- Greater Than, Floating-Point Greater Than (GT, FG) For fixed-point Compare instructions, (RA) > SI or (RB) (signed comparison) or (RA) >u UI or (RB) (unsigned comparison). For floating-point Compare instructions, (FRA) > (FRB).

2- Equal, Floating-Point Equal (EQ, FE) For fixed-point Compare instructions, (RA) = SI, UI, or (RB). For floating-point Compare instructions, (FRA) = (FRB).

3- Summary Overflow, Floating-Point Unordered (SO, FU) For fixed-point Compare instructions, this is a copy of the final state of XERSO at the completion of the instruction. For floating-point Compare instructions, one or both of (FRA) and (FRB) is a NaN.

请注意,这是在比较之后设置这些位的方式,因此这些位随后会被分支指令使用。如果您检查 subf 指令的引用,您可以看到哪些 CR 位也受到减法的影响,从而允许您像完成比较一样执行分支。

关于assembly - 如果没有比较指令,不相等如何分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36296748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com