meljun cortes rotate instructions

14
* Property of STI Page 1 of 14 Rotate Instruction 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)

Upload: meljun-cortes

Post on 22-Jan-2018

111 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: MELJUN CORTES Rotate instructions

* Property of STIPage 1 of 14

Rotate Instruction

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)

Page 2: MELJUN CORTES Rotate instructions

* Property of STIPage 2 of 14

Rotate Instruction

Computer Organization and Assembly Language

Rotate Instructions

Ø The different types of rotate instructions are:

v ROL instructionv ROR instructionv RCL instructionv RCR instruction

Page 3: MELJUN CORTES Rotate instructions

* Property of STIPage 3 of 14

Rotate Instruction

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 Operand

ROL byte ptr BETA, 1MM

ROL AL, 1register

ROL byte ptr BETA, CLMM

ROL AL, CLregister

ExampleDestination

Page 4: MELJUN CORTES Rotate instructions

* Property of STIPage 4 of 14

Rotate Instruction

Computer Organization and Assembly Language

Example - ROL Instruction

Example 1:MOV AL, 04HROL AL, 1

After execution, AL = 08H. The flags will be:

CF = 0, OF = 0

Example 2:MOV AL, 55HMOV CL, 03HROL AL, CL

After execution, AL = AAH. The flags will be:

CF = 0; OF = undefined

Page 5: MELJUN CORTES Rotate instructions

* Property of STIPage 5 of 14

Rotate Instruction

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: ROR D, CountØ Action:

CFOperand

ROR byte ptr BETA, 1MMROR AL, 1registerROR byte ptr BETA, CLMMROR AL, CLregister

ExampleDestination

Page 6: MELJUN CORTES Rotate instructions

* Property of STIPage 6 of 14

Rotate Instruction

Computer Organization and Assembly Language

Example - ROR Instruction

Example 1:MOV AL, 04HROR AL, 1

After execution, AL = 02H. The flags will be:

CF = 0, OF = 0

Example 2:MOV AL, 55HMOV CL, 03HROR AL, CL

After execution, AL = AAH. The flags will be:

CF = 0; OF = undefined

Page 7: MELJUN CORTES Rotate instructions

* Property of STIPage 7 of 14

Rotate Instruction

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, 5EHMOV CL, 02HROR AL, CLROL AL, CL

Page 8: MELJUN CORTES Rotate instructions

* Property of STIPage 8 of 14

Rotate Instruction

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: RCL D, CountØ Action:

CF Operand

RCL byte ptr BETA, 1MMRCL AL, 1registerRCL byte ptr BETA, CLMMRCL AL, CLregister

ExampleDestination

Page 9: MELJUN CORTES Rotate instructions

* Property of STIPage 9 of 14

Rotate Instruction

Computer Organization and Assembly Language

Example - RCL Instruction

Example 1:MOV AL, 04HRCL AL, 1

Assume that CF = 1. After execution, AL = 09H. The flags will be:

CF = 0, OF = 0

Example 2:MOV AL, 55HMOV CL, 03HRCL AL, CL

Assume CF = 0. After execution, AL = A9H. The flags will be:

CF = 0; OF = undefined

Page 10: MELJUN CORTES Rotate instructions

* Property of STIPage 10 of 14

Rotate Instruction

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:

CFOperand

RCR byte ptr BETA, 1MM

RCR AL, 1register

RCR byte ptr BETA, CLMMRCR AL, CLregister

ExampleDestination

Page 11: MELJUN CORTES Rotate instructions

* Property of STIPage 11 of 14

Rotate Instruction

Computer Organization and Assembly Language

Example – RCR Instruction

Example 1:MOV AL, 04HRCR AL, 1

Assume that CF = 1. After execution, AL = 82H. The flags will be:

CF = 0, OF = 1

Example 1:MOV AL, 55HMOV CL, 03HRCR AL, CL

Assume CF = 0. After execution, AL = 4AH. The flags will be:

CF = 1; OF = undefined

Page 12: MELJUN CORTES Rotate instructions

* Property of STIPage 12 of 14

Rotate Instruction

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, 7EHMOV CL, 02HROR AL, CLRCR AL, CLRCL AL, CLROL AL, CL

Page 13: MELJUN CORTES Rotate instructions

* Property of STIPage 13 of 14

Rotate Instruction

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:

MOV DX, FFFEHXOR SI, SIXCHG DX, SIDEC CXRCR word ptr [SI], CLMOV BX, [SI]MOV CX, 0009HROL BX, CL

4000HES =001EHSI =001BHDX =

2000HSS =0017HDI =0012HCX =

2000HDS =0035HSP =0019HBX =

3000HCS =0002HBP =0015HAX =

Page 14: MELJUN CORTES Rotate instructions

* Property of STIPage 14 of 14

Rotate Instruction

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, DB53HROR DX, 01HRCR DX, 01HROL DH, 01HROL DL, 01HRCL DX, 01HRCR DX, 01H

What will be DX after executing?