Professional Documents
Culture Documents
Experiment# 06
Student Name:
Roll Number:
Marks Obtained
Experiment evaluated by
H.O Bits 4 3 2 1 0
C 0
Sample Program:
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MOV ah, 88H ;88 has the binary weight of ‘10001000’
SHR ax,1 ;after moving the bit into the right, the MSB of 88 move to carry
;so it becomes 01000100 that is equal to ‘44H’
;Tip: please check carry flag that is it set or reset
; ** shifting 5 bit right
MOV cl,05h
MOV bx, 1234h
SHL bx,cl ;moving 5 bit to the right
.EXIT ;** terminating the program
Example:
Suppose DH contains 8Ah and CL contains 2. What are the values of BH and CF after the
instruction SHR DX, CL is executed?
Solution:
The value of DH in binary is 10001010 after two right shift CF = 2 the new value of DH is
obtained by erasing the rightmost two bits and adding two 0 bits to the left end, this DH =
00100010 = 22h
SAR
SAR operates like SHR with one difference the MSB retains its original value.
SAR destination, 1
And
SAR destination, CL
The effect of flag is the same as ROR.
H.O Bits 5 4 3 2 1 0
The ROL instruction sets the flag identical to RCL. Other than the source of the value shifted
into bit zero, this instruction behaves exactly like the RCL instruction. Don’t forget the
warning about the flags.
Like shl, the rol instruction is often useful for packing or unpacking data. For example,
suppose you want to extract bits 1…14 in ax and leave these bits in bit 0..4. The following
code sequence will both accomplish this:
Shr ax, 10
And ax, 1FH
Rol ax, 6
And ax, 1FH
SAMPLE PROGRAM
.model small
.stack 100h
.data
.code
Mov ah, 88h;88 has the binary weight of 10001000
ROL ax,1;rotating the bit into the left
;** rotating multiple bits
Mov cl, 04h
Mov bx, 1234h
Rol bx, cl; rotating 4 bits
.exit ;**terminating the program.
ROR
The ROR instruction relates to the RCR instruction in much the same way that the ROL
instruction relates to RCL that it is almost the same operation other than the source of the
input bit to the operand. Rather than shifting the previous carry flag into the H.O. bit of the
destination operand, ROR shifts bit zero into the H.O. bit.
The ROR instruction sets the flag identical to RCR. Other than the source of the bit shifts
into the H.O. bit, this instruction behaves exactly like the RCR instruction. Don’t forget the
warning about the flags!
OBSERVATION:
Sample program
.model small
.stack 100h
.data
.code
Main proc
Mov ah,88h ;88 has the binary weight of '10001000'
ROR ax,1; rotating the bit into the right
;** rotating multiple bit
Mov cl,04h;
Mov bx,1234h
ROR bx,cl ;rotating 4 bit
.exit ;**terminating the program
Task:
Write a program that show the following data translation
1-Shift left
2-Shift right
3-Rotate left
4-Rotate right
5-return to main menu
6-exit