CSE331 Lecture-09
CSE331 Lecture-09
SAL/SHL Shift SAL/SHL D, Shift the (D) left by the number of CF, PF, SF, ZF
arithmetic Count bit positions equal to Count and AF undefined
left/shift fill the vacated bits positions on OF undefined if
logical left the right with zeros count≠1
SHR Shift logical SHR D,Count Shift the (D) right by the number CF, PF, SF, ZF
right of bit positions equal to Count and AF undefined
fill the vacated bit positions on the OF undefined if
left with zeros count≠1
SAR Shift SAR D,Count Shift the (D) right by the number CF, PF, SF, ZF
arithmetic of bit positions equal to Count AF undefined
right and fill the vacated bit positions OF undefined if
on the left with the original most count≠1
significant bit.
4
SAL/SHL Instruction Set
SAL/SHL Destination, Count
This instruction performs shift left without conservation of sign
(sign may change)
If count is greater than 1 then it has to be stored in CL register.
Count 1 can be specified in instruction.
SHL DH, 1
A 0 is shifted into the rightmost bit position and the MSB is
shifted into CF.
For Example: SHL DH, 1. DH=47H= 0100 0111b and carry=1
After shift left DH=8EH, Carry=0
Before 1 0 1 0 0 0 1 1 1
CF
After 0 1 0 0 0 1 1 1 0
CF
5
SAL/SHL Instruction Set
Suppose DH contains 8Ah and CL contains 3. What are the
values of DH and of CF after the instruction SHL DH, CL is
executed?
MOV CL, 03H
SHL DH, CL
After execution, DH=50H and Carry=0
Before X 1 0 0 0 1 0 1 0
CF
After 1 0 0 0 1 0 1 0 0 0
CF
0 0 0 1 0 1 0 0 0 0
0 0 1 0 1 0 0 0 0 0
0 1 0 0 0 1 1 1 1 Before
CF
0 0 0 1 0 0 0 1 1 1 After
CF
8
SHR Instruction Set
Suppose DH contains 8Ah and CL contains 2. What are the
values of DH and of CF after the instruction SHR DH, CL is
executed?
MOV CL, 02H
SHR DH, CL
After execution, DH=22H and Carry=1
1 0 0 0 1 0 1 0 X Before
CF
0 1 0 0 0 1 0 1 0 After
0
CF
0 0 0 1 0 0 0 1 0 1
13
ROL Instruction Set
Before 1 0 1 0 0 0 1 1 1
CF
After 0 1 0 0 0 1 1 1 0
CF
14
ROL Instruction Set
ROL AX, 1
15
ROR Instruction Set
ROR Destination, Count
This instruction performs rotate bits right without carry.
If count is greater than 1 then it has to be stored in CL register.
Count 1 can be specified in instruction.
ROR DH, 1
The rightmost is shifted into the msb bit and also into the CF.
For Example: ROL DH, 1. DH=47H= 0100 0111b and carry=1
After shift left DH=A3H, Carry=1
0 1 0 0 0 1 1 1 1 Before
CF
1 0 1 0 0 0 1 1 1 After
CF
16
ROR Instruction Set
17
RCL Instruction Set
RCL Destination, Count
This instruction performs rotate bits left with carry.
If count is greater than 1 then it has to be stored in CL
register. Count 1 can be specified in instruction.
RCL DH, 1
For Example: RCL DH, 1. DH=47H= 0100 0111b and
carry=1
After shift left DH=8FH, Carry=0
Before 1 0 1 0 0 0 1 1 1
CF
After 0 1 0 0 0 1 1 1 1
CF
18
RCR Instruction Set
RCR Destination, Count
This instruction performs rotate bits right with carry.
If count is greater than 1 then it has to be stored in CL
register. Count 1 can be specified in instruction.
RCR DH, 1
For Example: ROR DH, 1. DH=47H= 0100 0111b
and carry=1
After shift left DH=A3H, Carry=1
0 1 0 0 0 1 1 1 1 Before
CF
1 0 1 0 0 0 1 1 1 After
CF
19
RCR Instruction Set
What is the result in BX and CF after execution of the
following instruction?
RCR BX, CL
Assume that, prior to execution of the instruction
CL=0416, BX=1234H, and CF=0.
(BX)=10000001001000112 =812316
(CF)= 02