SlideShare a Scribd company logo
Boolean and Comparison
Instructions
Operation Description
AND AND Destination, Source
OR OR Destination, Source
XOR XOR Destination, Source
NOT NOT Destination
TEST
Implied AND Destination, Source,
Only FLAGS changed
BT,BTC,BTR,
BTS  01/20/16 SHOUA IQBAL 1

 Bitwise AND (result placed in destination)
Mov al, 00001111b
And al, 00111011b al = ?
• al = 00001011b (0Bh)
Mov al, 6Dh
And al, 4Ah al = ?
• al = 48h
• AND with a 0 to clear bits
• AND with a 1 to preserve bits (bit extraction)
• Always clears the Overflow and Carry flags.
• May modify the Sign, Zero, and Parity flag
AND Instruction
01/20/16 SHOUA IQBAL 2
 Lowercase A (‘a’) is 61 0 1 1 0 0 0 0 1
 Uppercase A (‘A’) is 41 0 1 0 0 0 0 0 1
 Need to clear bit 5
Mov al, 61h
AND al, 11011111b ;(DFh)
;al = 41h
Application:Converting Characters
to Uppercase
01/20/16 SHOUA IQBAL 3

 Bitwise OR (result placed in destination)
Mov al, 0Fh
Or al, 61h al = ?
• al = 6Fh
Mov al, 3Dh
Or al, 74h al = ?
• al = 7Dh
 OR with 1 to set selected bits
 OR with 0 to preserve bits
 Always clears the Overflow and Carry Flags
 May modify the Sign, Zero, and Parity Flags
OR Instruction
01/20/16 SHOUA IQBAL 4
 Binary representation for 9 0 0 0 0 1 0 0 1
 Ascii 9 is 39h 0 0 1 1 1 0 0 1
 Need to set bits 4 and 5
Mov al, 9
OR al, 30h
;al = 00111001b (39h)
Application: Converting a Decimal
Digit (byte) to ASCII
01/20/16 SHOUA IQBAL 5
Application:Determining the sign of a
value by ORing register with itself
OR al, al
Zero Flag Sign Flag Value in AL is …
clear clear greater than 0
set clear equal to 0
clear set less than 0
01/20/16 SHOUA IQBAL 6

 Bitwise XOR (result stored in destination)
Mov al, 94h
XOR al, 37h al = ?
al = 10100011b
Mov al, 72h
Xor al, 0DCh al = ?
al = 10101110b
• XOR reverses itself when applied twice to the same
operand (data encryption)
• Clears the Overflow and Carry flags.
• May modify the sign, zero, and parity flags
XOR Instruction
01/20/16 SHOUA IQBAL 7

Indicates if the LOWEST BYTE of the result of a bitwise or
arithmetic operation has an even or odd number of 1 bits.
Mov al, 10110101b
XOR al, 0
; al unchanged parity flag clear (PO)
Mov al, 11001100b
XOR al, 0
; al unchanged parity flag set (PE)
Parity Flag
01/20/16 SHOUA IQBAL 8

Perform an XOR between upper-and lower bytes
Mov ax, 64C1h ;0110 0100 1100 0001
XOR ah, al
;ah = 10100101
Parity bit set (PE)
Application:How to check the
parity of 16-bit registers
01/20/16 SHOUA IQBAL 9
Perform an XOR between bytes
Mov eax, 56D764C1h
;0101 0110 1101 0111 0110 0100 1100 0001
XOR ah, al ;ah = 1010 0101
Shr eax, 8
XOR ah, al ;ah = 0111 0010
Shr eax, 8
XOR ah, al ;ah = 0010 0100
Parity bit set (PE)
Application: How to check the
parity of 32-bit registers
01/20/16 SHOUA IQBAL 10

 Toggles all bits in an operand
 No flags are affected
NOT Instruction
01/20/16 SHOUA IQBAL 11

 Implied AND (no registers are changed)
(flags may be modified)
• Valuable for determining if individual bits are set.
• Always clears the Overflow and Carry flags
• May modify the sign, zero, and parity flags
TEST Instruction
01/20/16 SHOUA IQBAL 12

 Implied SUB (no registers are changed)
(flags may be modified)
• May modify Overflow, Sign, Zero, Aux. Carry, and
Parity flags
CMP Instruction
01/20/16 SHOUA IQBAL 13
CMP Instruction Results
Zero Flag Carry Flag CMP Results
0 1
destination < source
CMP 5, 10
0 0
destination > source
CMP 105, 10
1 0
destination = source
CMP 10, 10
01/20/16 SHOUA IQBAL 14
CMP of Signed Integers
Flags CMP Results
SF ≠ OF destination < source
SF = OF destination > source
ZF = 1 destination = source
01/20/16 SHOUA IQBAL 15

1. Write a single instruction that clears the high 8 bits
of AX and does not change the low 8 bits.
AND AX, 00FFh
In Class Problems
01/20/16 SHOUA IQBAL 16

2. Write a single instruction that sets the high 8 bits of
AX and does not change the low 8 bits.
OR AX, FF00h
In Class Problems
01/20/16 SHOUA IQBAL 17

3. Write a single instruction that complements all the
bits in EAX (do not use the NOT instruction)
XOR EAX, FFFFFFFFh
In Class Problems
01/20/16 SHOUA IQBAL 18

4. Write instructions that set the Zero flag if the 32-bit
value in EAX is even, and clear the Zero flag if EAX
is odd.
TEST EAX, 0000 0000 0000 0000 0000 0000 0000
0001b
In Class Problems
01/20/16 SHOUA IQBAL 19

More Related Content

PPTX
8085 Pin Configuration
PPTX
Microprocessor 8086
PDF
Organization of the ibm personal computers
PPT
1327 Addressing Modes Of 8086
PPTX
Counters
PPTX
Stack and its usage in assembly language
PDF
Introduction to ibm pc assembly language
PPTX
Registers
8085 Pin Configuration
Microprocessor 8086
Organization of the ibm personal computers
1327 Addressing Modes Of 8086
Counters
Stack and its usage in assembly language
Introduction to ibm pc assembly language
Registers

What's hot (20)

PPTX
stack in assembally language
PDF
Representation of numbers and characters
PPTX
Text Mode Programming in Assembly
PDF
Chapter 6 Flow control Instructions
PPSX
USART - 8251 / usart-8251A Pallav Shukla
PPTX
QPSK(quadrature phase shift keying) Introduction
PPTX
8086 Microprocessor powerpoint
PPTX
8251 USART
PPTX
Salient featurs of 80386
PPT
PPTX
Evolution of Microprocessor
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
PPT
8086 micro processor
PPTX
Register Organisation of 8086 Microprocessor
PPTX
Instruction set of 8086
PPTX
Instruction Set of 8086 Microprocessor
PPTX
Evolution of microprocessors and 80486 Microprocessor.
PPTX
Addressing Modes Of 8086
PPTX
Instruction set of 8086
PPTX
Addressing Modes of 8085 Microprocessor
stack in assembally language
Representation of numbers and characters
Text Mode Programming in Assembly
Chapter 6 Flow control Instructions
USART - 8251 / usart-8251A Pallav Shukla
QPSK(quadrature phase shift keying) Introduction
8086 Microprocessor powerpoint
8251 USART
Salient featurs of 80386
Evolution of Microprocessor
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
8086 micro processor
Register Organisation of 8086 Microprocessor
Instruction set of 8086
Instruction Set of 8086 Microprocessor
Evolution of microprocessors and 80486 Microprocessor.
Addressing Modes Of 8086
Instruction set of 8086
Addressing Modes of 8085 Microprocessor
Ad

Similar to Boolean and comparison_instructions (20)

PPTX
Conditional Processing Boolean and Comparison Instructions-converted.pptx
PPTX
LEC 15 BOLEAN OPERATORS in comsats university.pptx
PPTX
LEC 15 BOLEAN OPERATORS in comsats university.pptx
PPTX
Lecture no 15
PPTX
Logical instructions (and, or, xor, not, test)
PPTX
Exp 7.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPT
chapt5 and 06assemblylanguagecodesandmachinelanguage.ppt
PPT
How Assembly works, and Logics made in Assembly language
PPTX
Arithmetic and logical instructions set
PDF
Computer Organization & Assembly Language Logic Instructions
PPT
Computer Organization & Assembly Language Logic Instructions
PPT
Assignment on alp
PPT
Assignment on alp
PPTX
X86 operation types
PPTX
Chap3 8086 logical
PPTX
Chapter3 8086inst logical 2
PPTX
Assembly Lab Sheet 5 About Status of Flag Register.pptx
PPT
Chapt 06
PPT
Chapt 06
PPTX
Arithmetic instructions
Conditional Processing Boolean and Comparison Instructions-converted.pptx
LEC 15 BOLEAN OPERATORS in comsats university.pptx
LEC 15 BOLEAN OPERATORS in comsats university.pptx
Lecture no 15
Logical instructions (and, or, xor, not, test)
Exp 7.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
chapt5 and 06assemblylanguagecodesandmachinelanguage.ppt
How Assembly works, and Logics made in Assembly language
Arithmetic and logical instructions set
Computer Organization & Assembly Language Logic Instructions
Computer Organization & Assembly Language Logic Instructions
Assignment on alp
Assignment on alp
X86 operation types
Chap3 8086 logical
Chapter3 8086inst logical 2
Assembly Lab Sheet 5 About Status of Flag Register.pptx
Chapt 06
Chapt 06
Arithmetic instructions
Ad

More from Army Public School and College -Faisal (20)

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Lesson notes of climatology university.
PDF
Sports Quiz easy sports quiz sports quiz
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Institutional Correction lecture only . . .
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Complications of Minimal Access Surgery at WLH
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Pharma ospi slides which help in ospi learning
Insiders guide to clinical Medicine.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Lesson notes of climatology university.
Sports Quiz easy sports quiz sports quiz
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Institutional Correction lecture only . . .
master seminar digital applications in india
Classroom Observation Tools for Teachers
STATICS OF THE RIGID BODIES Hibbelers.pdf
Computing-Curriculum for Schools in Ghana
Complications of Minimal Access Surgery at WLH
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
VCE English Exam - Section C Student Revision Booklet
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Pharma ospi slides which help in ospi learning

Boolean and comparison_instructions

  • 1. Boolean and Comparison Instructions Operation Description AND AND Destination, Source OR OR Destination, Source XOR XOR Destination, Source NOT NOT Destination TEST Implied AND Destination, Source, Only FLAGS changed BT,BTC,BTR, BTS  01/20/16 SHOUA IQBAL 1
  • 2.   Bitwise AND (result placed in destination) Mov al, 00001111b And al, 00111011b al = ? • al = 00001011b (0Bh) Mov al, 6Dh And al, 4Ah al = ? • al = 48h • AND with a 0 to clear bits • AND with a 1 to preserve bits (bit extraction) • Always clears the Overflow and Carry flags. • May modify the Sign, Zero, and Parity flag AND Instruction 01/20/16 SHOUA IQBAL 2
  • 3.  Lowercase A (‘a’) is 61 0 1 1 0 0 0 0 1  Uppercase A (‘A’) is 41 0 1 0 0 0 0 0 1  Need to clear bit 5 Mov al, 61h AND al, 11011111b ;(DFh) ;al = 41h Application:Converting Characters to Uppercase 01/20/16 SHOUA IQBAL 3
  • 4.   Bitwise OR (result placed in destination) Mov al, 0Fh Or al, 61h al = ? • al = 6Fh Mov al, 3Dh Or al, 74h al = ? • al = 7Dh  OR with 1 to set selected bits  OR with 0 to preserve bits  Always clears the Overflow and Carry Flags  May modify the Sign, Zero, and Parity Flags OR Instruction 01/20/16 SHOUA IQBAL 4
  • 5.  Binary representation for 9 0 0 0 0 1 0 0 1  Ascii 9 is 39h 0 0 1 1 1 0 0 1  Need to set bits 4 and 5 Mov al, 9 OR al, 30h ;al = 00111001b (39h) Application: Converting a Decimal Digit (byte) to ASCII 01/20/16 SHOUA IQBAL 5
  • 6. Application:Determining the sign of a value by ORing register with itself OR al, al Zero Flag Sign Flag Value in AL is … clear clear greater than 0 set clear equal to 0 clear set less than 0 01/20/16 SHOUA IQBAL 6
  • 7.   Bitwise XOR (result stored in destination) Mov al, 94h XOR al, 37h al = ? al = 10100011b Mov al, 72h Xor al, 0DCh al = ? al = 10101110b • XOR reverses itself when applied twice to the same operand (data encryption) • Clears the Overflow and Carry flags. • May modify the sign, zero, and parity flags XOR Instruction 01/20/16 SHOUA IQBAL 7
  • 8.  Indicates if the LOWEST BYTE of the result of a bitwise or arithmetic operation has an even or odd number of 1 bits. Mov al, 10110101b XOR al, 0 ; al unchanged parity flag clear (PO) Mov al, 11001100b XOR al, 0 ; al unchanged parity flag set (PE) Parity Flag 01/20/16 SHOUA IQBAL 8
  • 9.  Perform an XOR between upper-and lower bytes Mov ax, 64C1h ;0110 0100 1100 0001 XOR ah, al ;ah = 10100101 Parity bit set (PE) Application:How to check the parity of 16-bit registers 01/20/16 SHOUA IQBAL 9
  • 10. Perform an XOR between bytes Mov eax, 56D764C1h ;0101 0110 1101 0111 0110 0100 1100 0001 XOR ah, al ;ah = 1010 0101 Shr eax, 8 XOR ah, al ;ah = 0111 0010 Shr eax, 8 XOR ah, al ;ah = 0010 0100 Parity bit set (PE) Application: How to check the parity of 32-bit registers 01/20/16 SHOUA IQBAL 10
  • 11.   Toggles all bits in an operand  No flags are affected NOT Instruction 01/20/16 SHOUA IQBAL 11
  • 12.   Implied AND (no registers are changed) (flags may be modified) • Valuable for determining if individual bits are set. • Always clears the Overflow and Carry flags • May modify the sign, zero, and parity flags TEST Instruction 01/20/16 SHOUA IQBAL 12
  • 13.   Implied SUB (no registers are changed) (flags may be modified) • May modify Overflow, Sign, Zero, Aux. Carry, and Parity flags CMP Instruction 01/20/16 SHOUA IQBAL 13
  • 14. CMP Instruction Results Zero Flag Carry Flag CMP Results 0 1 destination < source CMP 5, 10 0 0 destination > source CMP 105, 10 1 0 destination = source CMP 10, 10 01/20/16 SHOUA IQBAL 14
  • 15. CMP of Signed Integers Flags CMP Results SF ≠ OF destination < source SF = OF destination > source ZF = 1 destination = source 01/20/16 SHOUA IQBAL 15
  • 16.  1. Write a single instruction that clears the high 8 bits of AX and does not change the low 8 bits. AND AX, 00FFh In Class Problems 01/20/16 SHOUA IQBAL 16
  • 17.  2. Write a single instruction that sets the high 8 bits of AX and does not change the low 8 bits. OR AX, FF00h In Class Problems 01/20/16 SHOUA IQBAL 17
  • 18.  3. Write a single instruction that complements all the bits in EAX (do not use the NOT instruction) XOR EAX, FFFFFFFFh In Class Problems 01/20/16 SHOUA IQBAL 18
  • 19.  4. Write instructions that set the Zero flag if the 32-bit value in EAX is even, and clear the Zero flag if EAX is odd. TEST EAX, 0000 0000 0000 0000 0000 0000 0000 0001b In Class Problems 01/20/16 SHOUA IQBAL 19