UMBC CMSC 313 -- Assembly Language Segment Previous | Next


Negative Numbers

We have looked at unsigned numbers so far. In the computer, unsigned numbers start at zero and go to 2n - 1. So, 216 goes from 0 to 65535. However, most things can have negative value and we want to represent them in the computer in such a way that we can perform all of the same mathematically operations, without worrying about whether the values are positive or negative.

To do that, we reserved the left-most bit to represent the sign of the number. Zero is a positive number and one is a negative number. That's the simple part. How to do the math operations was solved when they noticed that you can use the complement of the number. You simply change the sense of each bit. However, there is still a small problem with that (which is known as the 1's complement of the number.) It all works if we use the 2's complement of the number. To get the two's complement, simply add 1 to the 1's complement.

Example:

1011      decimal value is 11
0100      1's complement
0101      1's complement with 1 added = 2's complement = -11
Now when we add the two values, the result is zero:
  1011
 +0101
------
1 0000 (We throw away the overflow.)


Previous | Next

©2004, Gary L. Burt