ARM 在 EOR/XOR 和 AND 上携带标志

发布于 2024-07-29 17:14:57 字数 89 浏览 5 评论 0原文

我正在查找一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌能量女王 2024-08-05 17:14:57

我不相信正常的 AND/EOR 根本不会设置进位和溢出标志。 ANDS 和 EORS 变体(带设置的 AND/EOR)可以设置进位,但前提是右侧是移位操作数。 这些都不会影响溢出标志。

例如,

ANDS R0,R1,R2, LSR #1

将根据 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,

ANDS R0,R1,R2, LSR #1

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

聆听风音 2024-08-05 17:14:57

如果您决定继续使用 ARM 汇编程序,您需要一份 ARM ARM,即 ARM 架构参考手册。 有很多版本,每个版本都有自己的“特点”。 我建议尽可能多地收集,但那是另一个故事了。 有多种方法可以免费获取电子副本。 无论哪种方式:

并且
您需要设置 S 位,这对于 ARM 意味着使用 ANDS 而不是 AND。 对于拇指模式,您始终使用 ANDS,但例如,gas 拒绝在拇指模式下接受 ANDS(但始终将其反汇编为 ands)。

If S==1 and Rd == R15 then 
  CPSR=SPSR
else if S==1
  N Flag = Rd[31]
  Z Flag = if Rd == 0 then 1 else 0
  C Flag = shifter_carry_out
  V flag = unaffected

对于标志而言,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).

If S==1 and Rd == R15 then 
  CPSR=SPSR
else if S==1
  N Flag = Rd[31]
  Z Flag = if Rd == 0 then 1 else 0
  C Flag = shifter_carry_out
  V flag = unaffected

EOR is the same as AND when it comes to the flags

归属感 2024-08-05 17:14:57

正如其他发帖者所指出的,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).

不回头走下去 2024-08-05 17:14:57

请记住,您可以在操作后任意移动结果。 进位标志是根据桶形移位器的进位设置的。 溢出标志永远不会受到影响。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文