You are on page 1of 14

Computer Organization and Assembly Language

Rotate Instructions

Ø

rotate bits out into the other end of the
operand

Ø

can be classified by the direction of the
rotation (rotate to the left or rotate to the
right)

Rotate Instruction

* Property of STI
Page 1 of 14

Computer Organization and Assembly Language

Rotate Instructions

Ø

The different types of rotate instructions
are:
v
v
v
v

ROL instruction
ROR instruction
RCL instruction
RCR instruction

Rotate Instruction

* Property of STI
Page 2 of 14

Computer Organization and Assembly Language

The ROL Instruction

Ø

Ø
Ø

The ROL (Rotate Left) instruction rotates
to the left the destination operand by the
number of bits specified in the count
operand.
Format:
ROL D, Count
Action:

CF

Destination
register
MM
register
MM
Rotate Instruction

Operand

Example
ROL AL, CL
ROL byte ptr BETA, CL
ROL AL, 1
ROL byte ptr BETA, 1
* Property of STI
Page 3 of 14

Computer Organization and Assembly Language

Example - ROL Instruction
Example 1:
MOV AL, 04H
ROL AL, 1
After execution, AL = 08H. The flags will be:
CF = 0, OF = 0
Example 2:
MOV AL, 55H
MOV CL, 03H
ROL AL, CL
After execution, AL = AAH. The flags will be:
CF = 0; OF = undefined

Rotate Instruction

* Property of STI
Page 4 of 14

Computer Organization and Assembly Language

The ROR Instruction

Ø

The ROR (Rotate Right) instruction rotates
to the right the destination operand by the
number of bits specified in the count
operand.

Ø

Format:
Action:

Ø

ROR D, Count

Operand

Destination
register
MM
register
MM
Rotate Instruction

CF

Example
ROR AL, CL
ROR byte ptr BETA, CL
ROR AL, 1
ROR byte ptr BETA, 1
* Property of STI
Page 5 of 14

Computer Organization and Assembly Language

Example - ROR Instruction
Example 1:
MOV AL, 04H
ROR AL, 1
After execution, AL = 02H. The flags will be:
CF = 0, OF = 0
Example 2:
MOV AL, 55H
MOV CL, 03H
ROR AL, CL
After execution, AL = AAH. The flags will be:
CF = 0; OF = undefined

Rotate Instruction

* Property of STI
Page 6 of 14

Computer Organization and Assembly Language

Exercise

Ø

Execute the following instructions. Assume
that each instruction is dependent of one
another. Assume that all flags are initially
zero.
MOV AL, 5EH
MOV CL, 02H
ROR AL, CL
ROL AL, CL

Rotate Instruction

* Property of STI
Page 7 of 14

Computer Organization and Assembly Language

The RCL Instruction

Ø

The RCL (Rotate Left through Carry)
instruction rotates to the left the destination
operand by the number of bits specified in
the count operand. The carry flag is treated
as part of the rotate.

Ø

Format:
Action:

Ø

RCL D, Count

CF

Destination
register
MM
register
MM
Rotate Instruction

Operand

Example
RCL AL, CL
RCL byte ptr BETA, CL
RCL AL, 1
RCL byte ptr BETA, 1
* Property of STI
Page 8 of 14

Computer Organization and Assembly Language

Example - RCL Instruction
Example 1:
MOV AL, 04H
RCL AL, 1
Assume that CF = 1. After execution, AL =
09H. The flags will be:
CF = 0, OF = 0
Example 2:
MOV AL, 55H
MOV CL, 03H
RCL AL, CL
Assume CF = 0. After execution, AL = A9H.
The flags will be:
CF = 0; OF = undefined

Rotate Instruction

* Property of STI
Page 9 of 14

Computer Organization and Assembly Language

The RCR Instruction

Ø

The RCR (Rotate Right through Carry)
instruction rotates to the right the
destination operand by the number of bits
specified in the count operand. The carry
flag is treated as part of the rotate.

Ø

Format: RCR D, Count
Action:

Ø

Operand

CF

Destination
Example
register
RCR AL, CL
MM
RCR byte ptr BETA, CL
register
MM
Rotate Instruction

RCR AL, 1
RCR byte ptr BETA, 1
* Property of STI
Page 10 of 14

Computer Organization and Assembly Language

Example – RCR Instruction
Example 1:
MOV AL, 04H
RCR AL, 1
Assume that CF = 1. After execution, AL =
82H. The flags will be:
CF = 0, OF = 1
Example 1:
MOV AL, 55H
MOV CL, 03H
RCR AL, CL
Assume CF = 0. After execution, AL = 4AH.
The flags will be:
CF = 1; OF = undefined
Rotate Instruction

* Property of STI
Page 11 of 14

Computer Organization and Assembly Language

Quiz – Rotate Instructions

Ø

Execute the following instructions. Assume
that each instruction is dependent of one
another. Determine the status of the flags.
MOV AL, 7EH
MOV CL, 02H
ROR AL, CL
RCR AL, CL
RCL AL, CL
ROL AL, CL

Rotate Instruction

* Property of STI
Page 12 of 14

Computer Organization and Assembly Language

Program Tracing Example

Ø

Perform the indicated operation. Each
instruction is dependent of one another.
Whenever necessary, use the memory
map (handout) for additional data. Assume
the following register contents and assume
that all flags are initially 0:
AX = 0015H

BP = 0002H

CS = 3000H

BX = 0019H

SP = 0035H

DS = 2000H

CX = 0012H

DI = 0017H

SS = 2000H

DX = 001BH

SI = 001EH

ES = 4000H

MOV DX, FFFEH
XOR SI, SI
XCHG DX, SI
DEC CX
RCR word ptr [SI], CL
MOV BX, [SI]
MOV CX, 0009H
ROL BX, CL
Rotate Instruction

* Property of STI
Page 13 of 14

Computer Organization and Assembly Language

Program Tracing Exercise

Ø

Unless otherwise stated, determine the
contents of all the affected general-purpose
registers and the flags after executing the
following programs (assume that all
registers and flags are initially 0):
MOV DX, DB53H
ROR DX, 01H
RCR DX, 01H
ROL DH, 01H
ROL DL, 01H
RCL DX, 01H
RCR DX, 01H
What will be DX after executing?

Rotate Instruction

* Property of STI
Page 14 of 14