0% found this document useful (0 votes)
42 views30 pages

Lecture 4 Computer Arithematic (Sign Magnitude)

Uploaded by

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

Lecture 4 Computer Arithematic (Sign Magnitude)

Uploaded by

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

William Stallings

Computer Organization
and Architecture
8th Edition
Chapter 9
Computer Arithmetic

Book by : Computer, Architecture and Organizations, 8th Edition ,William Stalling


Original Slides by : Adrian J Pullin
Computer Arithmetic
Lecture Outcomes
Understanding of:
• Understand the distinction between the way in which numbers are represented (the
binary format) and the algorithms used for the basic arithmetic operations.
• Explain twos complement representation.
• Present an overview of the techniques for doing basic arithmetic operations in twos
complement notation.
• Understand the use of significand, base, and exponent in the representation of float-
ing-point numbers.
• Present an overview of the IEEE 754 standard for floating-point representation.
Arithmetic & Logic Unit

• THE DECIMAL SYSTEM (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)


The decimal system is said to have a base, or radix, of 10.
• HHEXADECIMAL NOTATION
• BINARY ARITHMATIC
Sign-Magnitude Representation

Twos Complement Representation


Range Extension

Sign Magnitude

Twos complement
ALU Inputs and Outputs
What is signed number?

• In computing, signed number representations are re-


quired to encode negative numbers in binary number
systems
Sign Magnitude
1’s Complement
Example
Two’s Complement
Example
Comparing the signed number systems
Decimal S.M. 1’s comp. 2’s comp.
7 0111 0111 0111
6 0110 0110 0110
• Here are all the 4-bit numbers 5 0101 0101 0101
in the different systems. 4 0100 0100 0100
3 0011 0011 0011
• Positive numbers are the same 2 0010 0010 0010
1 0001 0001 0001
in all three representations. 0 0000 0000 0000
• Signed magnitude and one’s -0 1000 1111 —
-1 1001 1110 1111
complement have two ways -2 1010 1101 1110
of representing 0. This makes -3
-4
1011
1100
1100
1011
1101
1100
things more complicated. -5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
-8 — — 1000
Converting signed numbers to decimal

• Convert 110101 to decimal, assuming this is a number in:

(a) signed magnitude format

(b) ones’ complement

(c) two’s complement


Signed overflow
• With two’s complement and a 4-bit adder, for example,
the largest represent able decimal number is +7, and the
smallest is -8.
• What if you try to compute 4 + 5, or (-4) + (-5)?

01 00 (+4) 1 1 00 (-4)
+ 01 01 (+5) + 1 01 1 (-5)
01 001 (-7) 1 01 1 1 (+7)
• We cannot just include the carry out to produce a five-digit result,
as for unsigned addition. If we did, (-4) + (-5) would result in +23!
• Also, unlike the case with unsigned numbers, the carry out cannot
be used to detect overflow.
– In the example on the left, the carry out is 0 but there is over-
flow.
– Conversely, there are situations where the carry out is 1 but
there is no overflow.
Detecting signed overflow
• The easiest way to detect signed overflow is to look at all
the sign bits.
01 00 (+4) 1 1 00 (-4)
+ 01 01 (+5) + 1 01 1 (-5)
01 001 (-7) 1 01 1 1 (+7)
• Overflow occurs only in the two situations above:
– If you add two positive numbers and get a negative
result.
– If you add two negative numbers and get a positive
result.
• Overflow cannot occur if you add a positive number to a
negative number.
Sign extension
• In everyday life, decimal numbers are assumed to have
an infinite number of 0s in front of them. This helps in
“lining up” numbers.
• To subtract 231 and 3, for instance, you can imagine:
231
- 003
228
• Overflow is still a problem, but signed overflow is very
different from the unsigned overflow we mentioned last
time.
• Sign extension is needed to properly “lengthen”negative
numbers.
Addition of Numbers in Twos Complement Representation
Subtraction of Numbers
in Twos Complement Representation (M – S)
Geometric Depiction of Twos Complement Integers
Why does this work?

• For n-bit numbers, the negation of B in two’s complement is


2n - B (this is one of the alternative ways of negating a two’s-complement
number). A-B = A + (-B)
n
= A + (2 - B)
= (A - B) + 2n
• If A  B, then (A - B) is a positive number, and 2n represents a carry out of 1.
Discarding this carry out is equivalent to subtracting 2n, which leaves us with
the desired result (A - B).
• If A  B, then (A - B) is a negative number and we have 2n - (A - B). This cor-
responds to the desired result, -(A - B), in two’s complement form.
Subtraction summary
• A good representation for negative numbers makes subtraction
hardware much easier to design.
– Two’s complement is used most often (although signed
magnitude shows up sometimes, such as in floating-point sys-
tems, which we’ll discuss on Wednesday).
– Using two’s complement, we can build a subtractor with
minor changes to the adder from.
– We can also make a single circuit which can both add and
subtract.
An adder subtractor circuit
Review Questions
 Briefly explain the following representations: sign magnitude, twos comple-
ment, biased.
Explain how to determine if a number is negative in the following representa-
tions: sign magnitude, twos complement, biased.
What is the sign-extension rule for twos complement numbers?
How can you form the negation of an integer in twos complement representa-
tion?
In general terms, when does the twos complement operation on an n-bit inte-
ger pro- duce the same integer?
Thank you

You might also like