0% found this document useful (0 votes)
8 views7 pages

Eric Ed440862

Uploaded by

Buican George
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Eric Ed440862

Uploaded by

Buican George
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

DOCUMENT RESUME

ED 440 862 SE 063 507

AUTHOR Luck, Carlos L.


TITLE A Graphical Teaching Tool for Understanding Two's
Complement.
PUB DATE 1998-08-00
NOTE 6p.; Paper presented at the International Conference of
Engineering Education (Rio de Janiero, Brazil, August 1998).
PUB TYPE Reports - Descriptive (141) Speeches/Meeting Papers (150)
EDRS PRICE MF01/PC01 Plus Postage.
DESCRIPTORS *Algebra; *Computer Literacy; Computer Science Education;
Engineering Education; *Graphing Calculators; Higher
Education; Mathematics Education

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)

Reproductions supplied by EDRS are the best that can be made


from the original document.
U.S. DEPARTMENT OF EDUCATION
PERMISSION TO REPRODUCE AND Office of Educational Research and Improvement
DISSEMINATE THIS MATERIAL HAS EDUCATIONAL RESOURCES INFORMATION
BEEN GRANTED BY CENTER (ERIC)
,,,ocument has been reproduced as
received from the person or organization
originating it.
Minor changes have been made to
improve reproduction quality.

TO THE EDUCATIONAL RESOURCES Points of view or opinions stated in this


INFORMATION CENTER (ERIC) document do not necessarily represent
official OERI position or policy.

A Graphical Teaching Tool for Understanding Two's Complement


CARLOS L. LUCK
Electrical Engineering Department
University of Southern Maine
Gorham, ME 04038-1088
luck@usm.maine.edu

Abstract Electrical Engineering program, along with logic gates,


boolean algebra, flip-flops and combinatorial logic, to name a
As part of the Electrical Engineering program, students are few. Over the years, students have rated this course as one of
typically introduced to Two's Complement algebra and the heaviest in the program, not because of the complexity of
representation, a method to include negative numbers in the the material, but rather due to the volume of content, the
binary representation of integers that is widely used in presence of a challenging laboratory component and it being
microprocessors and related digital systems. The traditional,
so early in the program.
procedural method to generate and evaluate the binary
pattern of negative numbers is often perceived to be non Consequently, relatively little time is spent in binary
intuitive and time-consuming when students perform it by algebra involving negative numbers, and when it does the
hand. focus is often on the process rather than the concept, simply
because the students are in the context of manipulating
A graphical method for the representation of binary individual bits or short strings of bits. Students learn quickly
numbers using Two's Complement algebra was presented to
that in order to "two's complement" a number, they must
an introductory class on microprocessors with great success. negate (or flip) each individual bit of the binary string and
The method is based on the principle of operation of the then add one to the result. But they often fail to distinguish
mechanical odometer and is particularly suited for such between the algebra, the process and the representation, or
tasks as the quick and reliable generation/evaluation of worse, carry misconceptions about them. The process itself
"small" negative numbers (-1, -2, etc.), detecting typical brings them no closer to understanding the concept. This
microprocessor conditions such as carry and overflow, and problem is observed later in the program, when the students
performing the common arithmetic operations of adding, take a course on microprocessors, which makes extensive use
subtracting, incrementing and decrementing. Two important of Two's Complement algebra in its assembly programming.
educational goals were achieved with this method. First, the
graphical representation allowed the students to grasp the Having taught microprocessors for several years, I
principles rather than to focus on the process. Second, the recognize the problem and this paper reports on my efforts to
ability to quickly and reliably generate small negative address it. The paper discusses an alternative method of
numbers proved to be a valuable skill for assembly presenting the concept and indicates how students benefit
programming in the laboratory, since small address offsets from this approach.
are conzmonplace in branching instructions.
2 The Concept
1 Introduction
Manipulation of binary numbers follows the same rules used
Not unlike other subjects and concepts in engineering, Two's in the manipulation of decimal numbers: to increment a
Complement algebra and representation are introduced in number with the right-most digit having the highest symbol
earlier courses and then fully explored later in the program. (in the decimal case 9), we return it to zero, index the digit
That in itself is not a problem. On the contrary, revisiting an immediately to its left and propagate the process to the left as
earlier topic helps a student to approach it with a fresh needed. The only difference is that binary numbers have 2
perspective and solidify the concept. The problem we have symbols instead of 10. When dealing with larger numbers
experienced is in the way Two's Complement is normally (thus long and tedious strings of l's and 0's), we often cluster
presented. 4 consecutive bits to create the hexadecimal representation
Two's Complement is one among a variety of methods (24 = 16, i.e. 4 bits can represent 16 distinct, sequential
designed to represent negative integers in digital systems. As symbols). In hexadecimal, we use 0-9 for the first 10 symbols
such, it is typically introduced in the first digital course of the and A-F for the remaining 6 symbols in the representation.

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

0 0 As a transition to motivate the final solution, it is useful to


-1 analyze the following method. The idea stems from the desire
11110000 1
2 1110 F 0 000 2 to establish a natural sequence of numbers from the
11011E 12 minimum value to the maximum value along the wheel, such
001
3 that additions and subtractions can be performed irrespective
1101 of the sign of the number. Since there are N=2" numbers on
-4 101$ 471
10 4 the wheel and only one zero is to be present, the remaining
patterns for positive and negative numbers total an odd
1010A 5 010
9 6 quantity. We choose to have the positive side one value less
1001 8 7 011' 5
than the negative side to compensate, meaning that the range
10000111 6 of numbers will be from -N/2 to +N/2-1. Furthermore, the
-7 7 minimum number will match the minimum binary
FIGURE 3. One's Complement Representation
representation of all-zeros and the maximum number will
match the maximum representation of all-ones.
As with all other methods of representation, the inverse The principle can be conceived graphically as taking a
process is identical, credit to the binary nature of the straight line with a scale spanning the representation from -
representation. In other words, the positive number is N/2 to +N/2-1 and wrapping it around the wheel, analogous
obtained by "one's complementing" the negative pattern. The to the unsigned concept in Figure 1. As a result, the
leftmost bit functions as a flag to differentiate between numerical value in this representation is obtained by
positive and negative numbers just like in the Sign and subtracting N/2 from the unsigned binary pattern, thus the
term N/2 Bias. Since the bias is carried equally in every
Magnitude method.
value, arithmetic operations can be performed exactly as in
As a result of the procedure, however, the order of the the unsigned case, requiring no extra hardware beyond the
negative numbers is reversed, making it more suitable for simple arithmetic engine used to manipulate unsigned
arithmetic operations in the sense of navigating the wheel as numbers. Negative numbers make up. the lower half of the
previously discussed. Yet it still contains the inconvenience representation (identified by the leading bit equal to zero) and
of double representation for the number zero. Whenever there positive numbers take the upper half (leading bit equal to
is a crossing between the positive and the negative sides, the one), as seen in Figure 4.
wheel must be turned one extra position to compensate for However, this convenience comes at a price. Unlike all
the double zero. Graphically, the conversion from positive to previous methods, positive numbers are represented
negative (and vice-versa) can be obtained as a mirror image differently between the signed and unsigned cases. The final
about the vertical diameter line (Figure 3). method aims at fixing this problem.

-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:

&ice or trieen trio 17.10LS/04 41A lqqb)


O. REPRODUCTION RELEASE:
In order to disseminate as widely as possible theiy aril egret:ant materials of interest to the educational community, document: announced is The
recninly ab*ecticlaTed of the ERIC sysktre, Reweave in ft/4Am (RIL), are usually made available to users In relcrcikho, ntiprOdUCed paper copy,
and electronic media. and sold through the poOtiment Reproduction SOM+20 (MRS). Credit IC given to the source of GOA document and,
reprodudion release is granted, one of the following notices is affixed to the document

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

-0 The EDUCATIONAL RESOURCES -3 THE EDUC.ATIONAL RESOURCES -7 THE EDUCATIONAL RESOURCES


tIs70RMATION CENTER (ERIC) 'NFORMATION CENTER (ERIC) INFORMATION CENTER (ERIC)

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

Clocuritob KVAtsvid as ImOtaltio prodded re/product] ea qua/ merits.


If pEllriltion u istirecttles Is warded. kJ re box IA deed*, etettottotto ea of otoccuoca it/a 1.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy