0% found this document useful (0 votes)
86 views8 pages

Lab - Sheet - EEE 391 - Exp5

This document provides an introduction to shift, rotate, and loop operations in assembly language. It describes the difference between shift and rotate commands, and provides examples of shift left (SHL), shift right (SHR), arithmetic shift left (SAL), arithmetic shift right (SAR), rotate left (ROL), and rotate right (ROR) instructions. It also introduces loop commands for repeating operations using a count register, and provides examples for incrementing a value, finding the greatest common divisor, and waiting for a period of time. Sample assembly language programs are given to demonstrate these concepts.

Uploaded by

Mehedi Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views8 pages

Lab - Sheet - EEE 391 - Exp5

This document provides an introduction to shift, rotate, and loop operations in assembly language. It describes the difference between shift and rotate commands, and provides examples of shift left (SHL), shift right (SHR), arithmetic shift left (SAL), arithmetic shift right (SAR), rotate left (ROL), and rotate right (ROR) instructions. It also introduces loop commands for repeating operations using a count register, and provides examples for incrementing a value, finding the greatest common divisor, and waiting for a period of time. Sample assembly language programs are given to demonstrate these concepts.

Uploaded by

Mehedi Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Bangabandhu Sheikh Mujibur Rahman Science & Technology University

Department of Electrical & Electronic Engineering


Laboratory Experiment Sheet
Course No: EEE 391
Course Title: Microprocessor Interfacing and System Design LAB

Experiment No: 05
Experiment Name: Introduction of Rotate, Shift and LOOPs in assembly
language.

Objective:

[1] To get familiar with Rotate and Shift commands in assembly


language.

[2] To introduce LOOP operation in complex program.

[3] To get familiar with SHR, SHL, SAR, SAL, ROL, ROR, RCL, RCR
instructions in assembly language.

Introduction:

Shift and Rotate command:

Shift and Rotate commands are used to convert a number to another form where
some bits are shifted or rotated. Basic difference between shift and rotate is shift
command makes “fall of” bits at the end of register. Where rotate command makes
“Wrap around” at the end of the register. There are both arithmetic (SAL and SAR)
and logical (SHL and SHR) shift instructions. Graphical operation for these commands
are shown below.

MSB LSB

CF Data 0

SHL (Shift Logical Left)

0 Data CF

SHR (Shift Logical Right)

MSB
LSB

CF Data 0
SAL (Shift Arithmetic Left)

Data CF

SAR (Shift Arithmetic Right)

CF DATA

ROL (Rotate Left)

Data CF

ROR (Rotate Right)

CF Data

RCL (Rotate Through Carry Left)

Data CF

RCR (Rotate Through Carry Right)

Some simple codes can be given to clarify the idea.

MOV CL, 03H ;


MOV AX, 02F3H ; In binary 0000 0010 1111 0011
SHR AX, CL ; In binary 0000 0000 0101 1110

In this procedure, SHR commands inserts 0’s from right side. Each
time a 0 is inserted left most bit is vanished from register content.

MOV CL, 03H ;


MOV AX, 82F3H ; In binary 1000 0010 1111 0011
SAR AX, CL ; In binary 1111 0000 0101 1110
In this procedure, SHR commands inserts MSB content from right side.
Each time it is inserted left most bit is vanished from register content.

MOV CL, 03H ;


MOV AX, 82F3H ; In binary 1000 0010 1111 0011
ROR AX, CL ; In binary 0111 0000 0101 1110

The whole procedure can be visualized as follows.

1 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1

0 1 1 1 0 0 0 0 0 1 0 1 1 1 1 0

Here rotate by 3 operation is shown. It is clearly seen that every bit is


assigned to a new position that is 3 places away from previous one.
Unlike the shift command no right bit is destroyed. It is placed in the
leftmost position.

Student Work:

(a) Program 1:

CODE SEGMENT

ASSUME CS: CODE


MOV CL, 02H
MOV AX, 105AH
SHL AX, CL
HLT

CODE ENDS
END

Obtain AX register value in write the previous value and present value
in binary form. What type of operation is this?

(b) Program 2:
CODE SEGMENT

ASSUME CS: CODE

MOV CL, 04H

MOV AX, 564AH

SAL AX, CL

HLT

CODE ENDS

END

Obtain AX register value in write the previous value and present value
in binary form. What type of operation is this?

(c) Program 3:

CODE SEGMENT

ASSUME CS: CODE

MOV CL, 04H

MOV AX, 564AH

ROL AX, CL

HLT

CODE ENDS

END

Obtain AX register value in write the previous value and present value
in binary form. What type of operation is this?

(d) Program 4:

CODE SEGMENT

ASSUME CS: CODE

MOV CL, 04H


MOV AX, 564AH

RCL AX, CL

HLT

CODE ENDS

END

Obtain AX register value in write the previous value and present value
in binary form. What type of operation is this?

(e) Perform for similar values of AX and CL with SHR, SAR. RCR,ROR
command.

LOOP in assembly language:

Loop commands are used to perform same operation again and again.
This is like for, while type instructions in ‘C’ or ‘MATLAB’. A common
example can be shown as,

MOV CX, 0100D

MOV AX, 564AH

Lev: DEC AX

Loop LEV

HLT

Here CX acts as a count register. Loop Lev instruction leads instruction


to go back to Lev level until CX is zero. Each time Lev level is executed
CX is decreased by 1. Loop command can be used for waiting
purposes. Such as,

MOV CX, 0100D

Wt: NOP

Loop Wt

HLT
Here the loop is executed until CX is zero. If 1 loop takes 1ms, the
program will wait for 100ms.

Student Work:

(a) Program 1:

CODE SEGMENT

ASSUME CS: CODE

MOV AX, 1025H

MOV BX, 475AH

MOV CX, 50H

Lev: INC AX

DEC BX

LOOP Lev

HLT

CODE ENDS

END

Observe the operation of this code. What happens when the loop is
executed again and again.

(b) Program 2: This code is to find GCD of two numbers.

CODE SEGMENT

ASSUME CS: CODE

MOV AX, 08H

MOV BX, 3H

Lev: XOR DX, DX

DIV BX
MOV AX, BX

MOV BX, DX

CMP DX, 0H

JNZ Lev

HLT

CODE ENDS

END

Here GCD of 8 and 3 are found. You can change the values of AX and
BX and obtain the result for any other values.

Homework:

1. Suppose x = 25 and y = 18. Add y with x for 20 times.

2. Multiply 12 by 6 until result is below 3000H. If result is greater


than this, divide the result by 2 for 3 times.

3. Find Least Common Multiplier of 12H and 25H.

4. Find GCD of 18D4H and 220H.

You might also like