ARM 在 EOR/XOR 和 AND 上携带标志
我正在查找一些 ARM 程序集,我注意到 EOR/XOR 和 AND 都设置了 C 和 O 标志。 这是如何运作的? 它们总是被清除吗? 他们设定了什么条件?
I was looking up some ARM assembly and i notice EOR/XOR and AND all set the C and O flag. How does that work? Are they always cleared? what conditions are they set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不相信正常的 AND/EOR 根本不会设置进位和溢出标志。 ANDS 和 EORS 变体(带设置的 AND/EOR)可以设置进位,但前提是右侧是移位操作数。 这些都不会影响溢出标志。
例如,
将根据 R2 的 b0 设置进位。 如果该位为 1(即 R2 为奇数),则进位将被设置。
请参阅此处了解详细信息(第 3 章,指令集)。
I don't believe the normal AND/EOR set the carry and overflow flags at all. The ANDS and EORS variants (AND/EOR with set) can set carry but only if the right hand side is a shifted operand. Neither of these affect the overflow flag at all.
For example,
will set carry depending on b0 of R2. If the bit was 1 (i.e., R2 was odd), carry will be set.
See here for the gory details (chapter 3, the instruction set).
如果您决定继续使用 ARM 汇编程序,您需要一份 ARM ARM,即 ARM 架构参考手册。 有很多版本,每个版本都有自己的“特点”。 我建议尽可能多地收集,但那是另一个故事了。 有多种方法可以免费获取电子副本。 无论哪种方式:
并且
您需要设置 S 位,这对于 ARM 意味着使用 ANDS 而不是 AND。 对于拇指模式,您始终使用 ANDS,但例如,gas 拒绝在拇指模式下接受 ANDS(但始终将其反汇编为 ands)。
对于标志而言,EOR 与 AND 相同
If you decide to continue with ARM assembler you need a copy of the ARM ARM, which is the ARM Architecture Reference Manual. There are many versions and each have their own "features". I recommend collecting as many as you can but thats another story. There are a number of ways to get an electronic copy for free. Either way:
AND
you need the S bit set which for ARM means use ANDS instead of AND. For thumb mode you are always using ANDS but gas for example refuses to accept ANDS in thumb mode (but always disassembles it as an ands).
EOR is the same as AND when it comes to the flags
正如其他发帖者所指出的,C 标志是根据在操作之前选择性地应用于源寄存器之一的移位来更新的。
V(溢出)标志不受这些指令的影响。
如果结果恰好为零,则设置 Z 标志;如果将结果视为二进制补码整数(即高位为 1),则设置 N 标志。
As other posters noted, the C flag is updated based on a shift that is optionally applied to one of the source registers before the operation.
The V (overflow) flag is unaffected by these instructions.
The Z flag is set if the result is exactly zero, and the N flag is set if the result is negative when viewed as a twos-complement integer (i.e. the high order bit is a one).
请记住,您可以在操作后任意移动结果。 进位标志是根据桶形移位器的进位设置的。 溢出标志永远不会受到影响。
Recall that you can arbitrarily shift the result following the operation. The carry flag is set based on the carry out from the barrel shifter. The overflow flag is never affected.