在AVR MCU上,状态寄存器中的S标志如何工作?

发布于 2025-01-24 07:16:49 字数 197 浏览 0 评论 0原文

V和S标志在Atmega328上如何工作?

ATMEGA328具有单独的符号,随身携带(C),2的补体溢出(V)和负(N)标志。 n是MSB(对应于其他处理器上的符号)。在数据表中无法很好地解释V标志的运行方式。据我了解,V通常计算为N⊕C。但是s在数据表中定义为v⊕n,这意味着它等于n⊕n⊕c或C。如果这是真的,那么拥有一个单独的标志就没有多大意义这里的东西。

How exactly do the V and S flags function on the ATMEGA328?

The ATMEGA328 has separate sign (S), carry (C), 2's complement overflow (V) and negative (N) flags. N is the MSB (corresponding to the sign bit on other processors). How exactly the V flag operates is not well explained in the datasheet. As I understand it, V is generally calculated as N⊕C. But S is defined in the datasheet as V⊕N which implies that it equals N⊕N⊕C or just C. If that's true then it doesn't make much sense to have a separate flag for it so I suspect I've misunderstood something here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

素罗衫 2025-01-31 07:16:49

v通常与n xor C不一样。

我通过查看手动,考虑到如果将0xff添加到0x02中会发生什么,以获得0x01。

  • C为1,因为0xff + 0x02 = 0x101,大于0xff,因此从添加的最重要位中有一个。
  • n将是0,因为它仅仅是结果的MSB。
  • V为0,因为如果两次的补体溢出发生,则定义为1。从两个补充的角度来看,我们只是添加了-1和2即可获得1,因此没有溢出。您可以通过仔细评估手册中的公式以计算V来确认这一点。

V is not generally the same as N XOR C.

I found a counterexample by looking at the ADC (Add with Carry) instruction in the manual and considering what would happen if you add 0xFF to 0x02 to get 0x01.

  • C would be 1 because 0xFF + 0x02 = 0x101, which is larger than 0xFF, so there is a carry from the most significant bit of the addition.
  • N would be 0 because it is simply the MSB of the result.
  • V would be 0 because it is defined to be 1 if two's complement overflow happened. From the perspective of two's complement, we simply added -1 and 2 to get 1, so there is no overflow. And you can confirm this by carefully evaluating the formula in the manual to calculate V.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文