When is CCR.V bit set?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

When is CCR.V bit set?

跳至解决方案
2,280 次查看
tupdegrove
Contributor III

General question not related to specific device.  I understand it is an arithmetic overflow in simplest terms.  Wondering the specific instances where it is set. Tried to research on net and found two answers.

 

1.  XOR of a carry into the sign bit and a carry out of the sign bit.

 

2. For addition, set when positive num + positive num = positive num and when negative num + negative num = positive num.

 

For subtraction, set when negative num - positive num = negative num and when positive num - negative num = negative num.

 

Anyone have a good description?

 

Tim

标签 (1)
0 项奖励
回复
1 解答
1,296 次查看
kef
Specialist I

In real world, when we add positive number to positive number we expect positive answer. Sudden negative result is oVerflow.

 

Adding negative to negative shouold give negative result. Positive means oVerflow. 

 

And subtractiion is similar to addition, except the sign of one of addend.

 

HC12 CPU manual gives such V bit equation for ADD

V = D15 M15 • /R15 + /D15 • /M15 R15

 

where D15 sign bit of one addend, M15 - sign bit of second addend, R15 - sign bit of result.

So adding V is set when either 1) both arguments are positive and result negrative, or 2) when both args negative and result positive.

 

 

for SUB

V = D15 • /M15 • /R15 + /D15 M15 R15

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,297 次查看
kef
Specialist I

In real world, when we add positive number to positive number we expect positive answer. Sudden negative result is oVerflow.

 

Adding negative to negative shouold give negative result. Positive means oVerflow. 

 

And subtractiion is similar to addition, except the sign of one of addend.

 

HC12 CPU manual gives such V bit equation for ADD

V = D15 M15 • /R15 + /D15 • /M15 R15

 

where D15 sign bit of one addend, M15 - sign bit of second addend, R15 - sign bit of result.

So adding V is set when either 1) both arguments are positive and result negrative, or 2) when both args negative and result positive.

 

 

for SUB

V = D15 • /M15 • /R15 + /D15 M15 R15

0 项奖励
回复
1,296 次查看
tupdegrove
Contributor III

Thank-you for the details.

 

Just for the record, I meant to say:

 

2. For addition, set when positive num + positive num = negative num...

 

Tim

0 项奖励
回复