0% found this document useful (0 votes)
52 views

MA251 Computer Organization and Architecture (3-0-0-6) : Spring 2011 Partha Sarathi Mandal

This document discusses shifters and how they are implemented in computer hardware. It explains that shifters are useful for manipulating bits and that shifting left is equivalent to multiplication by powers of two, while shifting right is equivalent to division. It describes how finite precision in computers requires different rules for shifting. It also distinguishes between logical shifts, which fill with zeros, and arithmetic shifts, which preserve the sign bit when shifting right on signed numbers. The document concludes by showing a circuit design for a shifter that can perform both left/right logical shifts and arithmetic right shifts.

Uploaded by

Udit Agarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

MA251 Computer Organization and Architecture (3-0-0-6) : Spring 2011 Partha Sarathi Mandal

This document discusses shifters and how they are implemented in computer hardware. It explains that shifters are useful for manipulating bits and that shifting left is equivalent to multiplication by powers of two, while shifting right is equivalent to division. It describes how finite precision in computers requires different rules for shifting. It also distinguishes between logical shifts, which fill with zeros, and arithmetic shifts, which preserve the sign bit when shifting right on signed numbers. The document concludes by showing a circuit design for a shifter that can perform both left/right logical shifts and arithmetic right shifts.

Uploaded by

Udit Agarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

MA251 Computer Organization and

Architecture [3-0-0-6]

Lecture 6: Shifter
Spring 2011
Partha Sarathi Mandal
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 select
line) can select between A or B.
Shifters (left)
• Shifting (e.g., left shifting 0011 yields 0110) useful
for:
– Manipulating bits
• Shift left once is same as multiplying by 2
– Example: 0011 (3) becomes 0110 (6)
– Why? Essentially appending a 0 -- Note that
multiplying decimal number by 10 accomplished just
be 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 number
by B.
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 divides
by B. The digit removed is the remainder, which
will be between 0 and B- 1.
Shifters: Finite precision arithmetic
• Computers represent numbers in fixed sizes.
• Adding a digit at the right necessarily means discarding a
digit 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 desired
answer at all.
• Rules are different when finite precision arithmetic is
involved.
• If the leftmost digit is significant, shifting left no longer
multiplies by B.
Arithmetic & Logical Shift
• When shifting right, we must supply a digit on the left.
When shifting unsigned or positive numbers, supplying a
zero on the left produces the expected result. Such a
shift 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 for
negative numbers. Such a shift is called an arithmetic
shift.
Shifters
• A shifter is a combinational circuit with one or more
inputs and an equal number of outputs. The outputs
are shifted with respect to the inputs.
• If only a shift left or a shift right is required, no gates
are needed; such a shift can be accomplished with
wires.
Shifters
• If we combine a shift left and a shift right then
gates are needed; such a shift cannot be
accomplished with only wires.
Left and right shift in a circuit
• This circuit can shift the input bits left or right,
depending on which control line is active.
Capturing the bit shifted out
• it can be made available for inspection.
• In the following fig adds an OR gate to capture
the bit shifted out.
• For the circuit shown, this will be D3 for a left
shift or D0 for a right shift.
Shifter with sign bit
• So far we have no way to deal with the sign bit
when performing a right shift on signed data. In
other 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.
Shifter with sign bit
• A fourth control line is added for arithmetic right shift.
• An OR gate drives the RIGHT control line when either an
arithmetic or a logical right shift is commanded.
• A second OR gate drives the copy function for the leftmost
bit when an arithmetic right shift is commanded.

You might also like