Mosaic
Well-Known Member
Is there an 'elegant' way to handle addition (only) in signed 8 bit asm math while keeping the max limits to 127 and -127?
It seems I have to code for 6 possibilities.
eg.
5 + 2 = +7 : double +ve
-5 + (-2) = -7 : double -ve
5 + (-2) = +3 :+ve and -ve
-5 + 2 = -3 : -ve and +ve
5 + (-6) = -1 , zero crossing to -ve
-5+ 6 = +1 , zero crossing to +ve
and then apply the max limits of +127 and -127.
So this involves evaluating the signs of each integer, clearing all the integer signs (bit7) doing the 'correct' addition or subtraction and applying the limits and then applying the correct sign. Zero crossing results will need two's complement to 'fix' the results to signed values.
This seems quite complicated, perhaps there is a better way?
It seems I have to code for 6 possibilities.
eg.
5 + 2 = +7 : double +ve
-5 + (-2) = -7 : double -ve
5 + (-2) = +3 :+ve and -ve
-5 + 2 = -3 : -ve and +ve
5 + (-6) = -1 , zero crossing to -ve
-5+ 6 = +1 , zero crossing to +ve
and then apply the max limits of +127 and -127.
So this involves evaluating the signs of each integer, clearing all the integer signs (bit7) doing the 'correct' addition or subtraction and applying the limits and then applying the correct sign. Zero crossing results will need two's complement to 'fix' the results to signed values.
This seems quite complicated, perhaps there is a better way?
Last edited: