[CST-2] Comp.Arch 2001 p8 q10
William R Sowerbutts
will@sowerbutts.com
Wed, 6 Jun 2001 17:59:24 +0100
My solution was to check the top bits of each word you are about to sum - if
any of them are set then you could overflow. One OR, one AND, one branch if
nonzero.
Since then it's been pointed out that a better solution is to AND out the
bottom bit of each 8-bit value, XOR them together (four one-bit sums) and
check that these are the bottom bits in the 32-bit sum. Also check the carry
bit. This checks for overflow on each 8-bit register, and is much better than
my solution. Damn.
Will
On Wed, Jun 06, 2001 at 05:36:30PM +0100, Andrei Legostaev wrote:
>
>Did anyone get the algorithm to detect overflow in today's Comp.Arch
>question?
>
>Please share - otherwise I'll spend the next week trying to work it out!
>
>A
>
>
>
>_______________________________________________
>CST-2 mailing list
>CST-2@srcf.ucam.org
>http://www.srcf.ucam.org/mailman/listinfo/cst-2
_________________________________________________________________________
William R Sowerbutts will@sowerbutts.com
Coder / Guru / Nrrrd http://sowerbutts.com
main(){char*s=">#=0> ^#X@#@^7=";int c=0,m;for(;c<15;c++)for
(m=-1;m<7;putchar(m++/6&c%3/2?10:s[c]-31&1<<m?42:32));}