Eric Ed440862
Eric Ed440862
ABSTRACT
As part of the Electrical Engineering program at the
Univesity of Southern Maine, students are typically introduced to Two's
Complement algebra and representation, a method to include negative numbers
in the binary representation of integers that is widely used in
al.:z.roprccessors and related digital systems. The traditional; procedural
method to generate and evaluate the binary pattern of negative numbers is
often perceived to be nonintuitive and time-consuming when students perform
it by hand. A graphical method for the representation of binary numbers using
Two's Complement algebra was presented to an introductory class on
microprocessors with great success. The method is based on the principle of
operation of the mechanical odometer and is particularly suited for such
tasks as quick and reliable generation/evaluation of "small" negative numbers
(-1, -2, etc.), detecting typical microprocessor conditions such as carry and
overflow, and performing the common arithmetic operations of adding,
subtracting, incrementing and decrementing. Two important educational goals
were achieved with this method. First, the graphical representation allowed
the students to grasp the principles rather than to focus on the process.
Second, the ability to quickly and reliably generate small negative numbers
proved to be a valuable skill for assembly programming in the laboratory,
since small address offsets are commonplace in branching instructions.
Contains 10 references. (Author/CCM)
2
BEST COPY AVAILABLE
0 1 2 3 45 6 7 8 9 10 11 12 13 14 15
15 0
111100
1110E 0 000
1106E 12 001
110k 3 001
1011 4 010 4
10119 5010
6
1001 8 7 011
100(1011
9 6
8 7
FIGURE I. Unsigned Representation
But unlike our abstract view of numbers as points on an 2.1 Sign and Magnitude
infinite straight line, the finite nature of the physical
implementation of numbers in a digital system makes it more The left-most bit represents the sign (0 for positive, I for
appropriate to conceive the topology of the representation as negative) and the remaining bits represent the magnitude as
circular rather than linear. This characteristic is embedded in in the unsigned case. Figure 2 illustrates the concept, with the
the design of digital systems through a feature referred to as decimal values (the meaning) on the outside and the binary/
"end-around," i.e. when the value of a number has reached its hexadecimal values (the representation) on the inside.
maximum range, an increment causes it to return to the This method is easy to be conceived and recognized by
minimum value. It is a mechanism analogous to mechanical the students, but it has two disadvantages. First, the turning
counters such as vehicle odometers (those that have not yet wheel concept is disrupted since negative numbers grow in
been replaced by digital counters), in which numbers are the opposite directions as the positive numbers, making it
marked on the surface of a wheel and a full revolution (or a harder to design an arithmetic unit to manipulate those
full sequence of indexed revolutions in case of multiple numbers in additions and subtractions. Second, there is the
digits) brings it back to zero. inconvenience of double representation for the number zero.
In fact, the mechanical analogy is the very basis for the Graphically, the conversion from positive to negative (and
graphical representation discussed in this paper. A simple vice-versa) can be obtained as the diametrically opposed
way to conceive this notion is to take a straight line with a pattern on the wheel.
scale ranging from zero to the maximum number in the
representation and wrap it around the wheel. For instance, in 2.2 One's Complement
a 4-bit system, the 16 values are marked on a wheel equally
The representation of a negative number is obtained by
spaced and in sequence, such that the highest value (15 in
complementing bit-by-bit the binary pattern of its
decimal or F in hexadecimal) becomes adjacent to zero.
corresponding positive number (i.e. the magnitude).
Incrementing and adding (decrementing and subtracting) are
viewed as navigating along the wheel in the clockwise
(counterclockwise) direction! -7 0
1
Figure 1 illustrates the concept above. Inside the wheel 11110000
the binary pattern of each number is depicted, along with its -5 1110
E
F 0 000 2
1
hexadecimal equivalent. Outside the wheel the decimal 11% 20011
number is shown, product of wrapping the scaled line around -4 3
110% 3 001
the wheel, starting at zero. Some of the most recent textbooks
in digital logic present the concept of the number wheel, -3 iota
recognizing its power as an explanation tool [9,10]. This 1010A9 5 010
representation is suitable for all-positive (known as unsigned) 6
1001 8 7 011 5
numbers.
-1
1000011 6
Negative numbers are represented by attributing negative
values to half of the available binary patterns. Several 0 7
methods are available: FIGURE 2. Sign and Magnitude Representation
3
BEST COPY AVAILABLE
2.3 N/2 Bias
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
7 -8
6 1111)00 -7
5 1110 F 0 000 -6
1101E 12
1101 3 001 -5
3 101$ 4010 -4
101# 5010
2 9 6 -3
1001 8 7 011
1
1000011 -2
0 -1
FIGURE 4. Na Bias Representation
4
BEST COPY AVAILABLE
2.4 Two's Complement reflecting an improved performance in exam questions
involving the manipulation of signed numbers. But in the
Textbooks present this method either procedurally (such as a microprocessor course, the concept helped in other ways too.
bias of one from the one's complement method to eliminate
the double zero) or as the principle that gives the
In an introductory course on microprocessors, it is
desirable to base it upon a commercial product that is simple
representation its name: x + x = 2n, such that is is the and inexpensive for the sake of experimentation by the
complement of x with respect to 2' and Tc defines the students and at the same time contains the fundamental
representation of the negative of x. Neither approach captures principles and operating features of modern, larger scale
easily the essence of what makes the method work and microprocessors used in computer systems. The usual choice
therefore create confusion, and sometimes misconceptions, is an 8-bit microprocessor, which is produced by several
in the minds of students. They fail to recognize the manufacturers with similar characteristics. The one adopted
distinction between the process of obtaining the negative of a in our program is the Motorola 6800 series.
number by "two's complementing" it and the representation
that establishes the numerical value assigned to a binary Since numbers are 8 bits wide and 28 = 256, unsigned
pattern. numbers are represented in the 0/255 range and signed
The graphical approach we are using with great success
numbers are represented in the -128/+127 range, following
to capture the essence of the method is to take the same Two's complement representation. 8-bit patterns can be
captured using 2 hexadecimal symbols, ranging from 00 to
desirable sequence from -N/2 to +N/2-1, as in the N/2 Bias
FF. The wheel concept helps conceive the representation and
method, and wrap it around the wheel in such a way that the
representation of positive numbers will coincide between the
assists in interpreting the principles of carry and overflow.
Carry occurs as a result of an arithmetic operation that causes
unsigned and the signed cases, as shown in Figure 5.
the number to cross the FF-00 mark, or the top of the wheel.
The approach explores the "end-around" feature to allow It represents the crossing of the boundary in the unsigned
a seamless transition between the positive and the negative representation. Overflow, on the other hand, occurs as a result
side of the wheel, using the standard concept of navigating of an arithmetic operation that causes the number cross the
the wheel clockwise for addition and counterclockwise for 7F--80 mark, or the bottom of the wheel. It represents the
subtraction. From the hardware point of view, further crossing of the boundary in the signed representation. Figure
simplification is obtained by treating subtraction as the 6 illustrates the notion.
special case of addition with the negative of the second term,
readily available by "two's complementing" it. All those But perhaps the most significant advantage of the wheel
features combined make two's complement the method of concept is in the quick and reliable generation and evaluation
choice in current design of microprocessors. of negative numbers of small magnitude. It is obtained by
mentally decrementing the number from zero until the
3 The Experience desired value is reached, which means navigating the wheel
in the counterclockwise direction. For instance, -1 is
The presentation of Two's Complement in the context of the represented by FF and -4 is obtained by counting backwards
wheel has resulted in a better understanding of the concept, FF, FE, FD, FC. Thus, the binary representation of -4 is FC.
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
-1 0
-2 11110000 1
1110 F 0 2
1
1101)
1100b 3 001
-5 10143 4
1010 5 010
9 6 5
-6 1001 8 7 011
-7 10000111
-8 7
FIGURE 5. Two's Complement Representation
5
BEST COPY AVAILABLE
Assembly language programming as a skill is becoming
nearly obsolete, credit to powerful compilers and smart
assemblers that hide the details of the code generation. On
the other hand, logic gates are not just the link from the
hardware of electronic circuits to the abstraction of boolean
algebra, but are also heavily involved in the design of digital
systems, connecting the various subsystems in a computer,
for example. Therefore, the two extremes of gate level and
processor level are used in conjunction during system design.
Two's Complement is caught in the middle and there is a risk
that it will be relegated to a level of detail hidden by the
programming software tools. However, since it is at the core
of how microprocessors manipulate binary numbers, a good
understanding of microprocessors can not be attained without
mastering this concept.
In this paper, a method is presented to explain the
mechanism behind Two's Complement algebra, without
having to focus on the procedure for generating negative
numbers. Over time, the details of the process (and there are
many which have not been addressed in this paper for the
Overflow sake of brevity) will fade, as the student moves on to different
areas, but hopefully the concept of the wheel will help to
FIGURE 6. 8-bit Two's Complement Representation with
Carry and Overflow keep Two's Complement as one of the key features bridging
the gap between the transistor logic and the user level view of
The representation FC is naturally obtained with the a computer.
traditional method of "two's complementing" 04 as well, but
References
students often take longer and lack confidence in the
correctness of the outcome. Speed and confidence are greater 1. Zvi Kohavi, Switching and Finite Automata Theory,
with the help of the wheel. McGraw-Hill, 2nd Edition, 1978.
But why would such a skill be desirable to begin with? 2. Fredrick Hill and Gerald Peterson, Introduction to
As it turns out, in assembly language programming, notably Switching Theory & Logical Design, John Wiley, 3rd
in the 6800 architecture, the target of branching instructions Edition, 1981.
is defined as an offset from the present position. In other
3. Joseph Cavanagh, Digital Computer Arithmetic,
words, the address of the next instruction to be executed in
the case of a branch is obtained by adding the given offset to McGraw-Hill, 1984.
the current location (program counter). Typically, branching 4. Frederick F. Driscoll, Introduction to 6800/68000
instructions are local and associated with small loops, such as Microprocessors, Delmar, 1987.
adding vector elements or looping with countdown to
produce a time delay. Consequently, the offset is often a 5. John P. Hayes, Computer Architecture and Organization,
positive number (for branching forward) or a negative 2nd Edition, 1988.
number (for branching backwards) with a small magnitude. 6. Barry B. Brey, Microprocessors and Peripherals,
In the laboratory, students use the wheel concept to quickly Merrill, 2nd Edition, 1988.
assemble and disassemble programs that contain branching
instructions, by mentally applying the procedure described in 7. Jack Quinn, The 6800 Microprocessor, Merrill, 1990.
the previous paragraph. 8. John Uffenbeck, Microcomputers and Microprocessors,
Prentice Hall, 2nd Edition, 1991.
4 Conclusion 9. Randy H. Katz, Contemporary Logic Design, Benjamin/
Cummings, 1994.
In a world in which principles are becoming increasingly
transparent to the students with access to sophisticated tools 10. John F. Wakerly, Digital Design: Principles and
and software, it is important that concepts be presented with Practices, Prentice-Hall, 2nd Edition, 1994.
an ever increasing focus on the meaning rather than the
process for learning to be more effective.
6
BEST COPY AVAILABLE
MAY-23-00 TUE 15:59 USMTECHCNTR FAX NO. 2077805129 P. 01
GO/ ZJi LOCRI L 15 bl4'Ly'Lb'Lb LKIU UblvILL rmuE 03
SE(2b-3--
U.S. Department of Education
Office of Educational Research and Improvement (OEM)
National Library of Education (NLE)
EPIC 1
Educational Resources Information Center (ERIC)
REPRODUCTION RELEASE
(Specific Document)
I. DOCUMENT IDENTIFICATION:
Title; A ci reackio dr,A7i-z.tfrodisi..9
wa.1.1.0,4111
________----------...
Corporg:e Source: Publication Date:
If Pry-11=km is Wonted to reproduce oral Cls5Srliklate itle identified document, pease VICO( ONE of ore foituumg three options and elan at the bottom
of the pazi.
The IMO salter macro below WE be Th4 **(Ws sitd:sr ;ham bokm ea be The mug sticur ahuNtl Wow IA 61
Mild to at 1.804 1 deginwsnla diked to al) Lewd 2A doouroesto MII111011111
atm tq cdI law] 25 dustoselp
PERMISSION TO REPRODUCE AND
PERMISSION TO REPRODUCE AND OfSSEMINATE THIS MATERIAL IN PERMISSION TO REPRODUCE AND
DISSEMINATE THIS MATERIAL HAS MICROFICHE. AND IN ELECTRONIC MEDIA DISSEMINATE THIS MATERIAL IN
BEEN GRANTED BY FOR ERIC COLt.MON SUtMenintRs ONLY. MICROFICHE ONLY HAS BEEN GRANTED BY
HAS BEEN GRANTED BY
(03 -
.ar sus* V. 5'6 OW. re a
I 2A 2B
Lever I Level 2A Level 2B
CoiMa bin fir LoAtl 1 !alma. pamitAg roprodundan elterk fax for Level 2A milieu. passiNits rampeuefion Chock ham reg (rm 20 rolowo_ paneling
X e crowhougoll 1 nicnfth.gr othw ERIC =no and cUmeroloslotOn attasrldts )(1 re stntsivc memo prad Mon end dimasentoaDonm rtticrfido ontr
M e l t NZ, r o a m * ad RIP,' Pay, of ErilG mnviV COMM sNldaamelarxuy
Amoy grant to the Educational ROSOurCuS infOnneaurr Center (ERIC) nonexclusive permission to rEDIDDUCO and arasominate Mis dOCCallent
as lrtrOcalfcd Om. RoPreductifin hem the ERIC miciafthe Of 0/0Uninig MO:to by persons other than ERIC employees eneite atom
Central= Midi= Pemeeelee hem the enP.Ydght col der: Exception is made forme-peg/ reproducffon by littred.s and oth. r &woo ogendoo
to sea& intbrr %Item MOO Of caciautors in mspanse m discrete (norms,
0Ls 4III
Sign Sktuttior.
here,V LOA al
Ortemmerituriswx:
please so bt.Me nq 207-700-6s-a.
evincefir 0403 .17
(Mee