Docsity

Computer Arithmatic-Programming and Computer Architechture-Lecture Slides, Slides of Computer Architecture and Organization

Partial preview of the text

Download Computer Arithmatic-Programming and Computer Architechture-Lecture Slides and more Slides Computer Architecture and Organization in PDF only on Docsity!

Computer Arithmetic

Objective

^ Our goal is to introduce the fundamentalissues related to the arithmetic operationsand circuits used to support computation incomputers. ^ Start with^ ■^ Number Systems^ ■^ Arithmetic Addition/Subtraction^ ■^ Arithmetic Multiplication^ ■^ Division^ ■^ Floating Point Numbers

Number System

0 ~ 9 0 ~ 1 0 ~ 7 0 ~ F

DecimalBinaryOctalHexadecimal

For any Number System

^ Positional notation:^ •^ General Equation^ •^ May contain a decimal point^ •^ Negative index for digits after decimal point ^ Examples^ •^ 1234.56 – if ambiguous, write (1234.56)

-^ Leading zeros cause no problems: 00001234.56 • AA n^ -^^1 n

…^ A - 2 A****.^ A 10

A … - 1 -^^2 A -^ m^ ++++^

A 1 -^ m

in which

0 <^ A i

<^ r^ and

“ .”^ is the

radix point

.

i i

a^ i

r ×

(^

) (^

(Number)

=^ r

∑^

+^ j =

-^^1

j j i i^ =^^0

i^

rA

rA

i = n (Integer Portion) + (Fraction Portion)

-^^1

j =^ -^ m

Negative Integer Representation  There exists a number of methods forrepresentation of negative integers: ■^ the^ sign-magnitude, ■^ radix complement,

and

■^ diminished radix complement.

Sign-Magnitude

^ The most significant bit (out of the n bits used torepresent the number) is used to represent the signof the number such that a “1’’ in the most significantbit position indicates a negative number while a "0"in the most significant bit position indicates apositive number. ^ The remaining

(n-1)^

bits are used to represent the

magnitude of the number.  Although simple, the sign-magnitude representationis complicated when performing arithmeticoperations.  In particular, the sign bit has to be dealt separatelyfrom the magnitude bits

Radix Complement

^ A positive number is represented the sameway as in the sign magnitude. ^ However, a negative number is representedusing the b’s complement (for base bnumbers).

Diminished Radix Complement  This representation is similar to the radixcomplement except for the fact that number“1” is added to the least significant bit aftercomplementing the digits of the number, asis done in the radix complement.  The main disadvantage of the diminishedradix representation is the need for acorrection factor whenever a carry isobtained from the most significant bit whileperforming arithmetic operations.

Sign Extension

^ To convert a “narrower” signed number to a “wider”one:^ ■^ Copy the bits of the narrower number into the lower bits^ ■^ Copy the sign bit from the narrower number into all of theremaining bits of the result ^ Example: Converting signed 8-bit byte to 32-bitword:

Orignal byte: - 00101011

Orignal byte: 45 00101011

Result word: 45

Result word: - 11111010

111111111111111111111111

Zero-Padding - for unsigned numbers ^ To convert a “narrower” unsigned number toa “wider” one^ ■^ Copy the bits of the narrower number into thelower bits^ ■^ Copy “zeros” into upper bits of wider number

Orignal byte: 193 11000001

Result word: 193 00101011

Orignal byte: 45 00101011

Result word: 45

zeros 000000000000000000000000

zeros

Two's Complement Arithmetic  Subtraction: ■ In 2's complement, subtraction can be performedin the same way addition is performed.

Hardware Structures for Addition andSubtraction of Signed Numbers:  The addition of two

n-bit^

numbers

A^ and

B

requires a basic hardware circuit that acceptsthree inputs, i.e.,

a ,^ bii

and c

. i-

^ These three bits represent respectively thetwo current bits of the numbers

A^ and

B^ (at

position

i)^ and the carry bit from the previous

bit position (at position

i-1).

^ The circuit should produce two outputs, i.e.,^ s and i^

c , representing respectively the sum i

and the carry

Multiple-Bit Adders

^ String together Full Adders to form a RippleAdder

AB^1 1 CC^12 S^1
AB^2 2 CC^23 S^2
AB^3 3 CC^34 S^3
AB^0 0 CC^01 S^0
  • AB^0 0 CC^01 S
  • AB^1 1 CC^12 S
  • AB^2 2 CC^23 S
  • AB^3 3 CC^34 S
  • How to Subtract with an Adder  Recall ■ Definition of subtraction: A-B = A + (-B) ■ Two’s Complement Negation Shortcut • -B = bit_invert(B)+