For example, if we are talking about of a 4-bit processor, where msb represents 'sign' ('1' represents -ve number and '0' represents +ve number), then we are left with 3 bits, which can be used to represent numbers from range -8 to +7. From the above image, the x-axis and y-axis represents numbers from -8 to 7
(which is nothing but the range of numbers which can be represented by 4-bit processor).
The contents of matrix shown in middle in white is the 'correct' sum of 2 numbers. For example, take a number '+6' (0110) from x-axis, and '-4' (1100) from y-axis. Now find the intersection of these numbers, and you will see the number '+2' in middle in white area. This says that '6' + '-4' = '+2' (0010). Try that for couple of more numbers whose result lie in white
area
Next, take number say '+6' (0110) from x-axis and '+2' (0010) from y-axis. '6' + '2' = '+8' (1000). Ooops. The binary representation of '+8' which 1000 represents a negative number '-8' (remember from above highlighted line, i.e. '1' represents -ve number). (Look for my
RISC-V Part 1a course to find out how to convert a binary pattern to its equivalent -ve numbers using 2's complement method)
Just imagine your personal calculator on your laptop (which has a 4-bit processor in it) giving a value of -8 for 6 + 2….Grrrr….Annoying…Right…..That brings us to the heading of this blog. Wanna quick solution to
detect overflow?
Consider below RISC-V assembly program to identify ‘overflows’ and take some action (like print an error message)