You are on page 1of 11

ECE 521:

Microprocessor System
Microprocessor Assembly Language Programming
What we will learn in this section:

Instruction sets: SHIFT instruction


Instruction sets: ROTATE instruction
Microprocessor Assembly
Language Programming

INSTRUCTION SETS: SHIFT INSTRUCTION


LSL (Logical Shift Left)
LSL instruction (LOGICAL SHIFT LEFT)
 The LSL instruction has the following format:
LSL Rd, Rm, Rn
 As each bit of Rm register is shifted left, the MSB is removed and the empty bits are filled
with zeros. The number of bits to be shifted left is given by Rn and the result is placed in
Rd register. The LSL does not updates the flags.
 Show the result of LSL in the following:
LDR R2,=0x00000010
LSL R0,R2,#4 ;R0=R2 is shifted left 4 times
;now, R0= 0x00000100, flags not updated
Solution:
 0x00000010 => 00000000 00000000 00000000 00010000
C = 0 (1st shift) 00000000 00000000 00000000 00100000
C = 0 (2nd shift) 00000000 00000000 00000000 01000000
C = 0 (3rd shift) 00000000 00000000 00000000 10000000
C = 0 (4th shift) 00000000 00000000 00000001 00000000

After shifting left FORTH times, R0 = 0x00000100 and C = 0.


LSLS Logical Shift Left (update the flags)
 The LSR instruction has the following format:
LSRS Rd, Rm, Rn
 As each bit of Rm register is shifted right, the LSB is copied to C flag and the empty bits are
filled with zeros. The number of bits to be shifted left is given by Rn and the result is placed in
Rd register. The LSRS updates the flags.
 Example 1:
LDR R0,=0x00000018
MOV R1, #12
LSLS R2,R0,R1 ;R2=R0 is shifted left R1 number of times
;now, R2= 0x000018000, C=0, N=0, Z=0
LSR Logical Shift Right

LSR instruction (LOGICAL SHIFT RIGHT)


 The LSR instruction has the following format:
LSR Rd, Rm, Rn
 The operand is shifted right bit by bit, and for every shift the LSB (least significant bit) will go
to the carry flag (C) and the MSB (most significant bit) is filled with 0. One can use an
immediate operand or a register to hold the number of times it is to be shifted.
 Show the result of LSR in the following:
LDR R2,=0x00001000
LSR R0,R2,#8 ;R0=R2 is shifted right 8 times ;now, R0= 0x00000010, C=0
LSRS Logical Shift Right (update the flags)

 The LSR instruction has the following format:

LSRS Rd, Rm, Rn


 As each bit of Rm register is shifted right, the LSB is copied to C flag and the empty bits
are filled with zeros. The number of bits to be shifted left is given by Rn and the result is
placed in Rd register. The LSRS updates the flags.
 Example 1:
LDR R2,=0x00001FFF
LSRS R0,R2,#8 ;R0=R2 is shifted right 8 times
;now, R0= 0x0000001F, C=1, N=0, Z=0
Microprocessor Assembly
Language Programming

INSTRUCTION SETS: ROTATE INSTRUCTION


ROR (Rotate Right)

ROR Rd,Rm,Rn ;Rd=rotate Rm right Rn bit positions


 As each bit of Rm register is shifted from left to right, they exit from the end
(LSB) and entered from left end (MSB).
 The number of bits to be rotated right is given by Rn and the result is placed
in Rd register. The ROR does not update the flags.
 LDR R2,=0x00000010
ROR R0,R2,#8 ;R0=R2 is rotated right 8 times
;now, R0 = 0x10000000, C=0

In rotate right, as bits are shifted from left to right they exit from the right end (LSB)
and enter the left end (MSB). In addition, as each bit exits the LSB, a copy of it is given to
the carry flag. In other words, in ROR the LSB is moved to the MSB and is also copied to
C flag, as shown in the diagram.
RORS Rotate Right (update the flags)
 The RORS instruction has the following format:
RORS Rd,Rm,Rn ;Rd=rotate Rm right Rn bit positions
 As each bit of Rm register shifts from left to right, they exit from the right end (LSB) and
enter from the left end (MSB). In addition as each bit exits the LSB, a copy of it is given
to C flag.
 The number of bits to be rotated right is given by Rn and the result is placed in Rd
register. The RORS updates the flags.
 Example:
LDR R2,=0x00000010
RORS R0,R2,#8 ;R0=R2 is rotated right 8 times
;now, R0= 0x01000000, C=0, N=0, Z=0
TUTORIAL 6
1) Find the contents of R3 after executing the following code:
MOV R1,#0x08
ROR R2,R1,#2
2) Find the contents of R4 after executing the following code:
MOV R2,#0x3
LSL R5,R3,#2
3) Using rotate instruction, show how you rotate left the fixed value of 0x33
total of a) 4, b) 8, and c) 12 times. Also give the value in the register after
the rotation.
4) What is content of R1 after executing following instruction, assume R1
contain 0x00000500
a) LSL R1,R1,8 b) LSR R1,R1.4

You might also like