Motorola M68000 User's Guide Page 25

  • Download
  • Add to my manuals
  • Print
  • Page
    / 256
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 24
Humber 5ystems 11
Representing Negative Values
So far in our discussion of number representations, we have only
been dealing with positive numbers. A method of representing negative
numbers in the computer must be introduced. You have already learned
that numbers are represented internally by binary digits. We must devise
a way of including the conventional minus sign used to indicate a
negative number, with the number itself. But how does a minus sign
translate into binary? Since numbers are either positive or negative, we can
indicate this fact by using a single binary digit. A negative number can be
indicated by using an extra bit rather than a minus sign. This may not work
as well on paper, but it is essential for a computer’s internal representations.
Numeric quantitites are normally restricted to fixed sizesa single
byte, a word, or some multiple number of words or bytes. It is not
practical to append an extrasign bit to a fixed unit of storage such
as a byte: the central processing unit (CPU) normally is restricted to
manipulating integral numbers of bytes, and this extra bit would force
the use of an extra complete byte. The solution is to sacrifice one of the
bits of our number for use as the sign bit. The size of the largest number
we can represent is reduced, but we can now represent the same number
of positive numbers as negative numbers.
By convention, if a number is negative we indicate this fact by in
cluding a sign bit equal to one. The sign bit is normally the leftmost, or
high-order, bit of the number. The simplest technique would be merely
to indicate the magnitude of the number in the remaining bits, setting the
sign bit to either one or zero to indicate a negative or positive number.
This representation, called sign magnitude, has been used on older com
puters. It has a number of disadvantages, the most prominent to a pro
grammer being the fact that both a positive and negative zero exist—both
100000002 and OOOOOOOO2 are zero values for a single byte number. With
out going into additional detail, suffice it to say that a better method is
needed.
Virtually all modern computers, including microprocessors, use a rep
resentation called twos complement. The sign bit is still used to indicate
whether a number is positive or negative, but the remaining bits do not
directly indicate the magnitude of the number if it is a negative number.
To represent a negative number in two’s complement, we first form the
ones complement of the number in its binary form. The one’s comple
ment is merely the number with all the one bits converted to zeros, and
all the zero bits converted to ones. The one’s complement of 011000112
is 100111002. So far this is quite simple. We are almost finished. To get
the twos complement we add one to the one’s complement. We perform
this addition just as we have done in the previous examples. To complete
the conversion of our example, we get:
Page view 24
1 2 ... 20 21 22 23 24 25 26 27 28 29 30 ... 255 256

Comments to this Manuals

No comments