Jeremy Leach
Senior Member
Ok, how do you add two words together, and detect overflow from the addition when you don't have any carry flag? e.g
Well the answer is so simple but it wasn't obvious to me until I worked it out! Maybe I'm thick, but the answer is : If LSW is less than any of Word1 or Word2 then there has been overflow. So can pick either of Word1 or Word2 and compare LSW to it. e.g
Can easily see the principle by using base 10 ...
When no overflow, e.g 1 + 3 = 4, the answer is always >= both of the numbers being added (ok !!).
When overflow, the answer is always < any of the numbers being added.
e.g
1 + 9 = 0
5 + 7 = 2
Code:
LSW = Word1 + Word2
Code:
LSW = Word1 + Word2
If LSW < Word1 Then
'Handle overflow
EndIf
When no overflow, e.g 1 + 3 = 4, the answer is always >= both of the numbers being added (ok !!).
When overflow, the answer is always < any of the numbers being added.
e.g
1 + 9 = 0
5 + 7 = 2
Last edited: