Sum a Signed Array

This function sums an array of signed dwords.

The program returns a dword as the final value, but allows the intermediate result to be larger than a dword can hold. It tracks the “result,” which is the dword total of the elements in the array, as well as an overflow/underflow “counter.” Each time the cumulative sum of the elements overflows (meaning it is more than 231-1, the highest value a signed dword can hold), the counter is incremented; each time the cumulative sum underflows (meaning it is less than -231, the lowest value a signed dword can hold), the counter is decremented. The net effect is that the counter functions ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.