Logical and Shift and Rotate Instructions 8086

LOGICAL Group of Instructions.

  1. Bit manipulation instruction

Bit Manipulation instructions : The instruction in this category operate on bits. The instruction can set, reset or even can test a particular bit. These instructions include :

Logical instructions: NOT, AND, OR, XOR and Test.

FORMAT Example Comments Flags Affected
NOT Source (R/M) MOV BL, 35h
NOT BL
BL=00110101
BL= 11001010
AND (R/M), Imm./ R/M MOV AL, 35h
AND AL, 0Fh
AL=00110101
AL=AL.0Fh= 00000101
CF=OF=0, AF=?
PF, SF, ZF updated
OR (R/M), Imm./ R/M MOV BL, 22h
MOV CL, FFh
OR BL, CL
BL=00010110
CL=11111111
BL=BL+CL=11111111
CF=OF=0, AF=?
PF, SF, ZF updated
XOR (R/M), Imm./ R/M MOV AL, 55h
XOR AL, FAh
AL=01010101
AL xor FAh=10100111
CF=OF=0, AF=?
PF, SF, ZF updated
TEST R?M, Imme/R/M MOV AL, 51h
TEST AL, 80h
AL=01010001
Test AL,80 test if the MSB is 0 or not; if msb is zer0 Z flag will be set.
CF=OF=0, AF=?
PF, SF, ZF updated

 

2.  Shift and Rotate operation

These instructions are used to perform logical or arithmetic shift and rotate operations where a bit of the data is involved. These instructions in shift group are: SHL, SAR, SHR, SAR

 

FORMAT Description Example Comments Flags Affected
SHL dest, count Shift logical left byte or word; No. of time shift count in CL MOV CL, 02
MOV BX, 89h
SHL BX, CL
CL= 00000010
BX=00000000 10001001
BX= 0000001000100100
 

SHL inserts zeros from the right

SAL dest, count Shift arithmetic left byte or word; No. of time shift count in CL MOV CL, 02
MOV BX, 89h
SHL BX, CL
CL= 00000010
BL=01001001
BL=00100100, CF= 1
SHL inserts zeros from the right, and MSB remains unaffected and the MSB is put in CF
SHR dest, count Shift logical right byte or word; No. of time shift count in CL MOV CL, 02
MOV BX, 89h
SHL BX, CL
CL= 00000010
BX= 10001001
BX= 00100010
Bits are shifted right with LSB moved in CF and zeros inserted from MSB
SAR dest, count Shift arithmetic right byte or word; No. of time shift count in CL MOV CL, 02
MOV BX, 89h
SHL BX, CL
CL= 00000010
BL= 10001001
BL= 00100100
MSB remains same i.e is copied again in MSB, i.e sign of number remains the same

 

3. Rotate instructions: ROL, ROR, RCL, RCR

ROL : Rotate left byte or word MSB to LSB and to Carry Flag [CF]. The operand to be rotated can be a register or memory location.

 

 

FORMAT Example Comments Flags Affected
ROL Dest, count MOV AL, 35
ROL AL, 03
AL 00100101
CF=1, AL=00101001
CF, OF

 

  • ROR : Rotate right byte or word LSB to MSB and to Carry Flag [CF]. The operand to be rotated can be a register or memory location.

 

 

FORMAT Example Comments Flags Affected
ROR Dest, count MOV AL, 35
ROR AL, 03
AL 00100101
CF=1, AL=10100100
CF, OF
  • RCL : Rotate left byte or word through carry flag MSB TO CF and CF to LSB4. The operand to be rotated can be a register or memory location.

 

FORMAT Example Comments Flags Affected
RCL Dest, count MOV AL, 35
RCL, AL 03
AL 00100101
CF=1, AL=00101001
CF, OF

 

  • RCR : Rotate right byte or word through carry flag LSB TO CF and CF to MSB. The operand to be rotated can be a register or memory location.

 

FORMAT Example Comments Flags Affected
RCR Dest, count MOV AL, 35
ROL AL, 03
Initially assume CF=0
AL 00100101
CF=0, AL=01000101
CF, OF

 

 

Example:

Write an ALP to convert the 8-bit packed BCD number stored in the memory into a binary number and store it in another memory location

Using assemble such as MASM Using KIT
Source variable X

Destination variable : Y

Assume source packed data at location : 2500:1000

Converted Binary to be stored at 2500: 1001

Data SEGMENT

    X db 35h

    Y db ?

Data ENDS

Code SEGMENT

ASSUME CS: code, DS: data

    MOV ax, data

    MOV ds, ax

    MOV AL, X

    MOV BL, AL

    AND AL, 0F0h

    MOV CL, 04

    ROR AL, CL

    MOV BH, 0Ah

    MUL BH

    AND BL, 0Fh

    ADD AL, BL

    MOV Y, AL

 Code ENDS

END

 

  MOV ax, 2500

MOV ds, ax

MOV AL, [1000]

MOV BL, AL

AND AL, 0F0h

MOV CL, 04

ROR AL, CL

MOV BH, 0Ah

MUL BH

AND BL, 0Fh

ADD AL, BL

MOV [1001], AL

HLT

 

 

Updated: December 14, 2020 — 9:50 am

Leave a Reply

Your email address will not be published. Required fields are marked *

care4you © 2020 Connect On Facebook DMCA.com Protection Status