lecturenotema251feb7

12
MA251 Computer Organization and Architecture [3-0-0-6] Lecture 6: Shifter Spring 2011 Partha Sarathi Mandal

Upload: udit-agarwal

Post on 08-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 1/12

MA251 Computer Organization and

Architecture [3-0-0-6]

Lecture 6: Shifter

Spring 2011Partha Sarathi Mandal

Page 2: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 2/12

Example: The Multiplexer/Data Selector

• Two 4-bit inputs, A (a3 a2 a1 a0), and B (b3 b2 b1 b0)

• 4-bit 2x1 mux (just four 2x1 muxes sharing a selectline) can select between A or B.

Page 3: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 3/12

Shifters (left)

• Shifting (e.g., left shifting 0011 yields 0110) usefulfor:– Manipulating bits

• Shift left once is same as multiplying by 2– Example: 0011 (3) becomes 0110 (6)

– Why? Essentially appending a 0 -- Note thatmultiplying decimal number by 10 accomplished justbe appending 0, i.e., by shifting left (55 becomes 550)

• For any positional number system of base B,adding a zero at the right multiplies the numberby B.

Page 4: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 4/12

Shifters (right)

• Removing a digit on the right of a decimal

number has the effect of dividing by ten; the

digit removed is the remainder.

• Thus, 157 / 10 = 15 with remainder 7.

• Shift right once same as dividing by 2.

Shifting any base B number to the right dividesby B. The digit removed is the remainder, which

will be between 0 and B- 1.

Page 5: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 5/12

Shifters: Finite precision arithmetic

• Computers represent numbers in fixed sizes.

• Adding a digit at the right necessarily means discarding adigit at the left.

• Consider an unsigned eight-bit number. We can shift

00000101 left one place and get the expected result:00001010– A non-significant zero was dropped on the left.

• Shifting 10100101 left produces 01001010, not the desiredanswer at all.

• Rules are different when finite precision arithmetic isinvolved.

• If the leftmost digit is significant, shifting left no longermultiplies by B.

Page 6: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 6/12

Arithmetic & Logical Shift

• When shifting right, we must supply a digit on the left.When shifting unsigned or positive numbers, supplying azero on the left produces the expected result. Such ashift is called a logical shift.

• A problem arises when shifting signed numbers.– Shifting 11110101 right produces 01111010 with remainder

one.

– The result is no longer negative.

• What is needed is to supply a one, not a zero, on the left

if the number is negative.• More generally, we want to replicate the sign bit,

supplying a zero for positive numbers and a one fornegative numbers. Such a shift is called an arithmeticshift.

Page 7: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 7/12

Shifters

• A shifter is a combinational circuit with one or moreinputs and an equal number of outputs. The outputsare shifted with respect to the inputs.

• If only a shift left or a shift right is required, no gatesare needed; such a shift can be accomplished withwires.

Page 8: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 8/12

Shifters

• If we combine a shift left and a shift right thengates are needed; such a shift cannot beaccomplished with only wires.

Page 9: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 9/12

Left and right shift in a circuit

• This circuit can shift the input bits left or right,

depending on which control line is active.

Page 10: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 10/12

Capturing the bit shifted out

• it can be made available for inspection.

• In the following fig adds an OR gate to capturethe bit shifted out.

• For the circuit shown, this will be D3 for a leftshift or D0 for a right shift.

Page 11: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 11/12

Shifter with sign bit

• So far we have no way to deal with the sign bitwhen performing a right shift on signed data. Inother words, we cannot yet do an arithmetic right

shift.• For a logical right shift, a zero is supplied at the

left.

• For an arithmetic shift, the leftmost bit of the

input is considered the sign bit.• It must be shifted to the right and also copied to

the leftmost bit of the output.

Page 12: LectureNoteMA251Feb7

8/7/2019 LectureNoteMA251Feb7

http://slidepdf.com/reader/full/lecturenotema251feb7 12/12