math - Binary arithmetic - addition with overflow -
when need subtract 2 numbers (x-y), can take 2's complement of y , add x. let's our system represents integers using byte (8 bits).
x = 7 = 00000111 y = 5 = 00000101 2's complement of 5
11111010 + 1 = 11111011 adding 2 =
00000111 11111011 __________ 100000010 there carryover. how 1 deal carryover?
if using 8 bits, means have range of -128 127. 7 , -5 , sum not fall outside range. not overflow.
that depends on trying do
if computing simple/single
+/-operationsthen overflow ignored
when need handle overflow/underflow
for example if need clamp result reason (usually safety of result range ...) carry flag of alu marks if overflow underflow occur. after set result max positive or negative value depending on inputs
sign,magnitude, operation(+,-). aome platforms have instructions automatically (saturated add,sub).another reason making
bigintoperations in case carry added+/-1higher operation (sign depends on operation)... result stays (add,adc,adc,adc,...)on modern languages/platforms not have direct alu flag register access anymore
sometimes can tap assembler can slower in cases computation itself. in case use approach 32bit alu in c++
cycarry flag
Comments
Post a Comment