简体   繁体   English

AVR组件添加溢出

[英]AVR Assembly Addition overflow

I know this is a newbie question, but I will ask it anyway because I couldn't find the answer. 我知道这是一个新手问题,但无论如何我都会提出,因为我找不到答案。 Here is the code I'm looking at. 这是我正在查看的代码。

LDI R15, 0x72     ;R15=114
LDI R16, 0x18     ;R16=24
ADD R16, R15      ;I know this causes signed overflow, but I'm not sure how avr handles this 
                  ;or if this number is unsigned

LDI R17, 0x91     ;R17=-111 if this is a signed number, which I assume it is. 
ADD R17, R16      ;no idea what the value is because of previous unkowns. 

I am basically trying to find what the SREG flags will be for this, but cannot due to the lack of understanding of the AVR. 我基本上是在尝试找到SREG标志,但是由于缺乏对AVR的了解而无法找到。 Please note that I don't have a microcontroller currently with me if not I would simply test to find the specified values. 请注意,如果没有,我目前没有微控制器,我只是测试以查找指定的值。

Thanks for the help! 谢谢您的帮助!

If you don't have an actual chip, you can still use a simulator. 如果您没有实际的芯片,仍然可以使用模拟器。 Or, horribile dictu, read the manual. 或者,可怕的话,请阅读手册。 It has the formulas for all the SREG bits. 它具有所有SREG位的公式。 It says: 它说:

H: Rd3·Rr3+Rr3·!R3+!R3·Rd3
   Set if there was a carry from bit 3; cleared otherwise
S: N ^ V, For signed tests.
V: Rd7·Rr7·!R7+!Rd7·!Rr7·R7
   Set if two's complement overflow resulted from the operation; cleared otherwise.
N: R7
   Set if MSB of the result is set; cleared otherwise.
Z: !R7· !R6 ·!R5· !R4 ·!R3 ·!R2 ·!R1 ·!R0
   Set if the result is $00; cleared otherwise.
C: Rd7 ·Rr7 +Rr7 ·!R7+ !R7 ·Rd7
   Set if there was carry from the MSB of the result; cleared otherwise.

As such, H=0 , S=1 , V=0 , N=1 , Z=0 and C=0 . 这样, H=0S=1V=0N=1Z=0C=0 This means, if you are using unsigned arithmetic you had no overflow ( C=0 ), the result ( 0x8a = 138 ) is valid. 这意味着,如果您使用的是无符号算术,则没有溢出( C=0 ),结果( 0x8a = 138 )是有效的。 Signed overflow did occur however ( S=1 ), since 0x8a signed means -118 . 但是,确实发生了签名溢出( S=1 ),因为0x8a签名意味着-118

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM