0% found this document useful (0 votes)
302 views10 pages

Shift and Rotate Instructions

The document explains various shift and rotate instructions used in assembly language including SHL, SHR, SAL, SAR, ROL, ROR, RCL and RCR. These instructions shift or rotate each bit in a value by a specified number of bit positions and some instructions also affect the carry flag.

Uploaded by

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

Shift and Rotate Instructions

The document explains various shift and rotate instructions used in assembly language including SHL, SHR, SAL, SAR, ROL, ROR, RCL and RCR. These instructions shift or rotate each bit in a value by a specified number of bit positions and some instructions also affect the carry flag.

Uploaded by

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

Shift and Rotate

Instructions

CH#7-(A_KHALIQ)
SHL (Shift Left) Instruction

Shifts each bit to the left, filling the lowest bit with 0. The
highest bit is moved to the carry flag. The bit that was in
carry flag is lost.

Permitted operands:
SHL dest,1
SHL dest,CL
SHL dest, immed8 ;80286 and higher
Desination operand can be 8, 16 or 32 bit register or memory
operand. CH#7-(A_KHALIQ)
SHL (Shift Left) Example

mov dl,1 ;dl =1


shl dl,1 ;dl=2
shl dl,1 ;dl=4
shl dl,1 ;dl=8

CH#7-(A_KHALIQ)
SHR (Shift Right) Instruction

Shift each bit to the right, replacing the highest bit with a 0. The
lowest bit is copied into the carry flag and the bit that was in
carry flag is lost.

mov dl,32 ;dl =32


shr dl,1 ;dl=16
shr dl,1 ;dl=8
shr dl,1 ;dl=4

CH#7-(A_KHALIQ)
SAL (Shift Airthmatic Left)
– Similar to SHL

CH#7-(A_KHALIQ)
SAR Shift Arithmetic Right
(for signed numbers)
Shift each instruction to the left and make a copy of the sign bit.

mov al,0f0h ;al = 11110000 (-16)


sar al,1 ;al = 11111000 (-8)

mov dx,8000h dx = -32768


sar dx,5 dx = -1024 (divide by 32)

CH#7-(A_KHALIQ)
Rotate Instructions
ROL (rotate Left)
Moves each bit to the left. The highest bit is copied both
into carry flag and into the lowest bit.

mov al,40h ;al = 01000000b


rol al,1 ;al = 10000000b CF = 0
rol al,1 ;al = 00000001b CF =1
rol al,1 ;al = 00000010b CF = 0
rol al,1 ;al = 00000100b CF = 0
rol al,1 ;al = 00001000b CF = 0
CH#7-(A_KHALIQ)
ROR (Rotate Right)
Moves each bit to the right. The lowest bit is copied into the
carry flag and into the highest bit at the same time.

mov al,01h ;al = 00000001b


ror al,1 ;al = 10000000b CF = 1
ror al,1 ;al = 01000000b CF = 0

CH#7-(A_KHALIQ)
RCL (Rotate Carry Left)

Shifts each bit to the left and copies the highest bit into the
Carry Flag, Carry Flag previous value is copied into lowest
bit of result.

CLC ;CF = 0
mov bl,88h ;BL = 10001000b
rcl bl,1 ;BL = 00010000b CF = 1
rcl bl,1 ;BL = 00100001b CF = 0

CH#7-(A_KHALIQ)
RCR (Rotate Carry Right)

Shift each bit to the right and copies the lowet bit into carry flag.
The carry Flag copies into the highest bit of the result.

stc ; CF =1
mov ah,10h ;AH = 00010000b, CF = 1
rcr ah,1 ;AH = 10001000b, CF = 0

CH#7-(A_KHALIQ)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy