AlbaLed Posted November 2, 2003 Share Posted November 2, 2003 Give a simple rule (to be implemented in hardware) to detect signed arithemtic overflow. If your solution involves examining whole numbers that is not simple neither cheap to implement. Enjoyyy Quote Link to comment Share on other sites More sharing options...
nonevent99 Posted November 2, 2003 Share Posted November 2, 2003 if the sign of the addends is the same, but they differ from the sign of the result. Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted November 2, 2003 Author Share Posted November 2, 2003 Nonevent what about if the addends have different sign? Quote Link to comment Share on other sites More sharing options...
nonevent99 Posted November 2, 2003 Share Posted November 2, 2003 I didn't think you could have an overflow when adding numbers of different sign. If A and B are of different sign, then wouldn't A + B be closer to zero than either A or B, and therefore within range? I'm talking about integer arithmetic. Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted November 2, 2003 Author Share Posted November 2, 2003 True nonevent, I should have phrased differently, when does addition overflow mean operation overflow in signed arithemtic. That is since we're using 2's complement than we can implement - by addition. My bad. Here is the answer We're only inspecting most significant bit for carry in carry out if carry in == carry out -> NO OVERFLOW if carry in != carry out -> OVERFLOW Hope this helps Quote Link to comment Share on other sites More sharing options...
nonevent99 Posted November 2, 2003 Share Posted November 2, 2003 Sorry, I don't understand. When you add two numbers, isn't the carry in on the far right hand side (LSB) always 0? Quote Link to comment Share on other sites More sharing options...
wood Posted November 3, 2003 Share Posted November 3, 2003 I didn't get too... what does carry in have to do with it here? Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted November 3, 2003 Author Share Posted November 3, 2003 we're analysing only the most significant bit, carry in = carry into the most significant bit carry out = carry that results from the most significant bit additions for example, most significan bit is on the left 1001 0111 most significan bit will have carry in AND carry out.=> no overflow 1001 1000 most significan bit will have no carry in AND carry out. => overflow Hard ?? Quote Link to comment Share on other sites More sharing options...
wood Posted November 3, 2003 Share Posted November 3, 2003 Ok... got it. Sounds neat. Quote Link to comment Share on other sites More sharing options...
nonevent99 Posted November 3, 2003 Share Posted November 3, 2003 Alba, that's a very nice solution. It differs from Brookshear's answer in his Computer Science / Overview textbook, but I think your algorithm works great. Thanks! Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted November 3, 2003 Author Share Posted November 3, 2003 Not my very own, I've heard it from a professor in school and I think I've seen it a couple of places on the net, not too many books talk about it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.