Chapter 7 Logic, Shift and Rotate Instructions (Part 1) - Daffodil ...

23
Chapter 7 Logic, Shift and Rotate Instructions (Part 1) PREPARED BY AHMED AL MAROUF LECTURER, CSE, DAFFODIL INTERNATIONAL UNIVERSITY (DIU) 1

Transcript of Chapter 7 Logic, Shift and Rotate Instructions (Part 1) - Daffodil ...

Chapter 7Logic, Shift and Rotate Instructions (Part 1)PREPARED BY

AHMED AL MAROUF

LECTURER, CSE, DAFFODIL INTERNATIONAL UNIVERSITY (DIU)

1

Ahmed Al Marouf
Pencil

OutlinePart 1 contains only

Logic Instructions AND

OR

XOR

NOT

Applications of Logic Instructions CLEAR

SET

COMPLEMENT /CHANGE

2

Logic Instructions Logic instructions has the ability to manipulate individual bits.

The binary values of 0 and 1 are treated as False and True, respectively.

Logic Operations for 8086 assembly language are: AND

OR

XOR and

NOT

When logic operation is applied to 8-bit or 16-bit operands, the result is obtained by applying the logic operation at each bit position.

3

Truth Table of Logic OperationsOperands Logic Operations

Operand 1 Operand 2 AND OR XOR NOT Op1

0 0 0 0 0 1

0 1 0 1 1 1

1 0 0 1 1 0

1 1 1 1 0 0

4

Examples

5

Assembly Instructions

6

Effect on Flags of Logic Instructions

7

Applications of Logic Instructions

1. Clearing bits

2. Setting bits

3. Complementing bits

These operations can be performed on individual bits.

8

Clearing bits Clearing means changing the bits as follow:

0 to 0

1 to 0

Therefore,

Masks for

Changed – 0

Unchanged - 1

9

Operands Logic Operations

Original Bit Mask AND

0 0 0

0 1 0

1 0 0

1 1 1

Setting bits Setting means changing the bits as follow:

0 to 1

1 to 1

Therefore,

Masks for

Changed – 1

Unchanged - 0

10

Operands Logic Operations

Original Bit Mask OR

0 0 0

0 1 1

1 0 1

1 1 1

Complementing bits Setting means changing the bits as follow:

0 to 1

1 to 0

Therefore,

Masks for

Changed – 1

Unchanged - 0

11

Operands Logic Operations

Original Bit Mask XOR

0 0 0

0 1 1

1 0 1

1 1 0

Use Logic Instructions as Mask

12

Examples

13

Examples

14

Examples

15

Other applications of Logic Instructions (1)

16

Other applications of Logic Instructions (2)

17

NOT Instruction

18

TEST Instruction

19

Example of Test Instruction

20

Exercise (Self-Study)

21

Exercise (Self-Study) Contd.

22

Thank you.

23