Lab - Sheet - EEE 391 - Exp5
Lab - Sheet - EEE 391 - Exp5
Experiment No: 05
Experiment Name: Introduction of Rotate, Shift and LOOPs in assembly
language.
Objective:
[3] To get familiar with SHR, SHL, SAR, SAL, ROL, ROR, RCL, RCR
instructions in assembly language.
Introduction:
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
0 Data CF
MSB
LSB
CF Data 0
SAL (Shift Arithmetic Left)
Data CF
CF DATA
Data CF
CF Data
Data CF
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.
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
Student Work:
(a) Program 1:
CODE SEGMENT
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
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
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
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 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,
Lev: DEC AX
Loop LEV
HLT
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
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.
CODE SEGMENT
MOV BX, 3H
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: