Mci Lecture 17
Mci Lecture 17
LOGICAL
ARITHMETIC
Note:The number of bit positions by which shifts and rotations are to
be done may be specified by a constant or may be indicated in an
another register.
LOGICAL SHIFT LEFT(LSL)
LSL Cont….
Logical shift left of a 32 –bit number causes it to
shift left ,a specified number of times,and the
vacant bits on the right are filled with zeros.The
last bit shifted out from the left is copied to the
carry flag
Eg:Left shift by one positions corresponds to
multiplication by two and left shift by five
implies multiplication by 32.
LOGICAL SHIFT RIGHT(LSR)
LSR Cont..
Logical shift right of a 32 –bit number causes it to shift right ,a
specified number of times,and the vacant bits on the left are filled with
zeros.The last bit shifted out from the right is copied to the carry
flag.Shifting right by one ,divides number by two.Two right shifts cause
a division by four.
ARITHMETIC SHIFT RIGHT(ASR)
ASR Cont….
ASR fills the vacant bit position on the left are filled with the MSB bit
of the original number.
This is nothing but a sign extension of data,because for positive
numbers MSB bit is zero and for negative numbers MSB bit is one.
Note:The is no instruction atithmatic shift left,because of not having an
application for it.
ROTATE RIGHT(ROR)
ROR Cont..
Here ,the data is moved right ,and the bits shifted out from right are
inserted back through the left .The last rotated out bit is available in the
carry flag.
Note:There is no rotate left instruction is available,because left rotation
by n times can be achieved by rotating to the right (32-n) times.
Example ,rotating 4 times to the left is achieved by rotating 32-4=28
times to the right.
ROTATE RIGHT EXTENDED(RRX)
RRXCont…
Here rotating right through the carry bit,meaning that the bit that
drops of from the right side is moved to C and the carry bit enters
through the left of data.
Note:
The number of bit positions by which shifts and
rotations are to be done may be specified by a
constant or may be indicated in an another
register.
EXAMPLES
LSL R2,#4
Shift left logically ,the content of R2 by 4 bit positions
ASR R5,#8
Shift right arithmetically ,the content of R2 by 4 bit positions.
ROR R1,R2
Rotate the content of R1,by the number specified by R2.
EXAMPLE
Given that
R1=0XEF00DE12
R2=0X0456123F
R5=4
R6=28
Find the result in the destination register ,when
the following instructions are executed.
1.LSL R1,#8
2.ASR R1,R5
3.ROR R2,R6
4.LSR R2,#5
LSL R1,#8
R5 contains 4.
Arithmetically right shifting R1 4 times.Also causes the MSB (1,for the
given number) to be replicated 4 times on the left,thus causing the sign
extension of the shifted number.
R1 now contains ????
Answer:
R1:= 0xFEF00DE1
ROR R2,R6
R6 contains 28.
Rotating R2 28 times to right is equivalent to rotating it 32-28 =4
times,to the left.