Sherenica
Sherenica

Reputation: 15

Assembly Language -Addition of two signed numbers

Dear Stackoverflow community

Question : Given two signed numbers x = 01111110 (base 2) and y = 00001000 (base 2) .Explain why x + y operation will result into wrong results?

My attempt : (Understanding) From my research about sign number magnitude the only way x + y will be wrong will be if the answer overflows into the sign.

Please can anyone help me, I have researched and read about sign magnitude, ones complement and twos complement ,but still find it very confusing.

Thank you very much for taking the time and patience to see my question.

Upvotes: 0

Views: 685

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126917

Assuming that your signed integers are 8 bit wide, it's exactly as you said: it's overflowing in the sign bit, which (in 2's complement) results in wraparound.

01111110 +
00001000 =
10000110

As you can see, summing the two positive values (126 and 8, they both have the sign bit not set) resulted in a negative value (it has the sign bit set; in 2's complement, it's -122), which is obviously wrong.

Upvotes: 2

Related Questions