For words and bytes, you can detect an overflow by testing if the result is less than what you added.
Due to trucation of a 16-bit word ...
$FF00 + $0180 = $0080
So the result will always be less than either of the values added if an overflow occurs.
I'm sure you could. But that's just not my way ...I think i can manage myself once i am sure abour the overflow
Which displays ...Code:;Initialize your hardware first A VAR WORD[2] B VAR WORD[2] Result VAR WORD[2] OVRFLOW32 VAR BIT ASM ; ===== Load 32bit Constant into DWORD ============================= MOVE?CD macro C32in, Dout ; Max= 4,294,967,296 MOVE?CB low C32in, Dout MOVE?CB low (C32in >> 8), Dout + 1 MOVE?CB low (C32in >> 16), Dout + 2 MOVE?CB low (C32in >> 24), Dout + 3 endm ENDASM @ MOVE?CD 0xEFFF8, _A ; Load 983,032 into A @ MOVE?CD 0x6FFE4, _B ; Load 458,724 into B GOSUB Add32 LCDOUT $FE,1, "A= ",HEX4 A[1],":",HEX4 A[0] LCDOUT $FE,$C0,"B= ",HEX4 B[1],":",HEX4 B[0] LCDOUT $FE,$90,"Res= ",HEX4 Result[1],":",HEX4 Result[0] LCDOUT $FE,$D0,"OVRFLOW32 = ", BIN1 OVRFLOW32 stop ; ===== Add 2 32bit variables ====================================== Add32: OVRFLOW32 = 0 Result[0] = A[0] + B[0] IF Result[0] < B[0] then Result[1] = 1 Result[1] = Result[1] + A[1] IF Result[1] < A[1] then OVRFLOW32 = 1 Result[1] = Result[1] + B[1] IF Result[1] < B[1] then OVRFLOW32 = 1 RETURNHTH,Code:A= 000E:FFF8 B= 0006:FFE4 Res= 0015:FFDC OVRFLOW32 = 0





Bookmarks