SlideShare a Scribd company logo
Computer Organization &
Assembly Language
Logic Instructions
Logic Instructions
 To manipulate individual bits
 Binary Value 0 treated as false
 Binary Value 1 treated as true
 In Assembly Language:
 AND
 OR
 XOR
 NOT
 TEST
2
Truth Tables
3
a b a AND b a OR b a XOR b
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
a NOT a
0 1
1 0
Examples
1. 1010 1010 AND 1111 0000 = 1010 0000
2. 1010 1010 OR 1111 0000 = 1111 1010
3. 1010 1010 XOR 1111 0000 = 0101 1010
4. NOT 1010 1010 = 0101 0101
4
Syntax
AND destination, source
OR destination, source
XOR destination, source
 Destination:
 Stores result
 Can be Register or Memory Location
 Source:
 May be a Constant, Register or Memory Location
5
Effects on Flags
 SF, ZF, PF reflects the result
 AF is undefined
 CF, OF = 0
6
MASK
 To modify only selective bits in destination, we
construct a source bit pattern known as MASK.
 To choose mask, use following properties:
 b AND 1 = b
 b AND 0 = 0
 b OR 1 = 1
 b OR 0 = b
 b XOR 0 = b
 b XOR 1 = ~b (complement of b)
Where b represents a bit (0 or 1)
7
MASK
 To choose mask, use following properties:
 b AND 1 = b
 b AND 0 = 0
 b OR 1 = 1
 b OR 0 = b
 b XOR 0 = b
 b XOR 1 = ~b (complement of b)
Where b represents a bit (0 or 1)
8
MASK
 To choose mask, use following properties:
 b AND 1 = b
 b AND 0 = 0
 b OR 1 = 1
 b OR 0 = b
 b XOR 0 = b
 b XOR 1 = ~b (complement of b)
Where b represents a bit (0 or 1)
9
MASK
 To choose mask, use following properties:
 b AND 1 = b
 b AND 0 = 0
 b OR 1 = 1
 b OR 0 = b
 b XOR 0 = b
 b XOR 1 = ~b (complement of b)
Where b represents a bit (0 or 1)
10
MASK
 To choose mask, use following properties:
 b AND 1 = b
 b AND 0 = 0
 b OR 1 = 1
 b OR 0 = b
 b XOR 0 = b
 b XOR 1 = ~b (complement of b)
Where b represents a bit (0 or 1)
11
MASK
 To choose mask, use following properties:
 b AND 1 = b
 b AND 0 = 0
 b OR 1 = 1
 b OR 0 = b
 b XOR 0 = b
 b XOR 1 = ~b (complement of b)
Where b represents a bit (0 or 1)
12
MASK
 To choose mask, use following properties:
 b AND 1 = b
 b AND 0 = 0
 b OR 1 = 1
 b OR 0 = b
 b XOR 0 = b
 b XOR 1 = ~b (complement of b)
Where b represents a bit (0 or 1)
13
Contd..
1. The AND instruction:
- May be used to clear specific destination bits
while preventing the others.
- A 0 mask bit clears the corresponding
destination bit.
- A 1 mask bit preserves the corresponding
destination bit.
14
Example 1
 Clear the sign bit of AL while leaving the other
bits unchanged.
 Solution:
AND AL, 7Fh
Where 7Fh (0111 1111) is the mask.
Suppose: AL = 0D4h Binary: 1101 0100
→
AND 1101 0100
0111 1111
= 0101 0100 54h
→
15
Contd..
2. The OR instruction:
- May be used to set specific destination bits
while preventing the others.
- A 1 mask bit sets the corresponding destination
bit.
- A 0 mask bit preserves the corresponding
destination bit.
16
Example 2
 Set the MSB and LSB of AL while preserving the
other bits.
 Solution:
OR AL, 81h
Where 81h (1000 0001) is the mask.
Let
AL = 42h Binary: 0100 0010
→
OR AL, 81h OR 0100 0010
→
1000 0001
= 1100 0011 C3h
→
17
Contd..
3. The XOR instruction:
- May be used to complement specific
destination bits while preventing the others.
- A 1 mask bit complements the corresponding
destination bit.
- A 0 mask bit preserves the corresponding
destination bit.
18
Example 3
 Change the sign bit of DX.
 Solution:
XOR DX, 8000h
Where 80h (1000 0000) is the mask.
DX = 7230h 0111 0010 0011 0000
→
XOR 0111 0010 0011 0000
1000 0000 0000 0000
= 1111 0010 0011 0000 F230h
→
19
Nibbles
 A nibble is a unit of data in computing that consists
of four bits. A bit is the smallest unit of data in a
computer and can have a value of either 0 or 1. A
nibble, being four bits, can represent 16 different
values (2^4 = 16), ranging from 0000 to 1111 in
binary notation.
 Four bits that are at the higher-order positions
within a byte (or word). In a byte, which is typically
composed of eight bits, the high nibble consists of
the four bits at positions 4-7 (counting from right to
left, where the rightmost bit is bit 0).
20
Nibbles contd…
 For example, consider the byte 1010 1101 in
binary notation. In this byte:
 The high nibble is 1010, corresponding to bits 4-7.
 The low nibble is 1101, corresponding to bits 0-3.
21
Converting an ASCII digit to a Number
 ASCII code for digit “0-9” is “30h-39h”
AND AL, 0Fh ;Clears the high nibble.
 How to convert decimal digit to ASCII code?
 Add 48 to every decimal digit.
 E.g. to convert 213 into ASCII code, just add 48 to 2 then
48 to 1 and lastly 48 to three
 So we get 50 49 51
22
23
Lowercase to Uppercase letter
 Lower case: 61h to 7Ah ( 97 to 122)
 Uppercase: 41h to 5Ah (65 to 90)
24
Clearing a Register
MOV AX, 0 ;machine code 3 bytes
OR
SUB AX, AX ;machine code 2 bytes
OR
XOR AX, AX ;machine code 2 bytes
25
Testing a Register for zero
CMP CX, 0
Is same like:
OR CX, CX ;sets ZF = 1 if CX is 0
26
NOT Instruction
 Performs the one’s complement operation on the
destination.
 Syntax:
NOT destination
 No effect on flags
 Example: Complement the bit in AX:
NOT AX
27
TEST Instruction
 Performs an AND operation without changing
destination i.e. only status flags updated.
 Syntax:
TEST destination, source
MOV AL, F0h ; AL = 1111 0000
TEST AL, 0Fh ; = 0000 1111
28
TEST Instruction
 Performs an AND operation without changing
destination i.e. only status flags updated.
 Syntax:
TEST destination, source
 Effects on flags:
 SF, ZF and PF reflects the results
 AF is undefined
 CF, OF = 0
29

More Related Content

PPT
How Assembly works, and Logics made in Assembly language
PPTX
Logical instructions (and, or, xor, not, test)
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
PPTX
Arithmetic and logical instructions set
PPTX
Arithmetic instructions
PPTX
LEC 15 BOLEAN OPERATORS in comsats university.pptx
PPTX
LEC 15 BOLEAN OPERATORS in comsats university.pptx
PPT
Boolean and comparison_instructions
How Assembly works, and Logics made in Assembly language
Logical instructions (and, or, xor, not, test)
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Arithmetic and logical instructions set
Arithmetic instructions
LEC 15 BOLEAN OPERATORS in comsats university.pptx
LEC 15 BOLEAN OPERATORS in comsats university.pptx
Boolean and comparison_instructions

Similar to Computer Organization & Assembly Language Logic Instructions (20)

PPT
Unit 2 8086 Instruction set.ppt notes good
PPT
8086 instruction set
PDF
10 -bits_and_bytes
PPT
Logic, shift and rotate instruction
PPT
Logic, shift and rotate instruction
PPTX
Hemanth143
PPT
8086-instruction-set-ppt
PPT
computer system architecture for control system.ppt
PPTX
Exp 7.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPT
Chapter 2 Part2 A
PPTX
Lecture 04 Logical Group of Instructions
PPTX
Lecture no 15
PPTX
Instruction 4.pptx
PPT
Chapter 2
PPTX
Conditional Processing Boolean and Comparison Instructions-converted.pptx
PPTX
Microprocessors-based systems (under graduate course) Lecture 4 of 9
PDF
Topic 6 - Programming in Assembly Language_230517_115118.pdf
PPT
Al2ed chapter9
DOC
POLITEKNIK MALAYSIA
PPT
Instruction set
Unit 2 8086 Instruction set.ppt notes good
8086 instruction set
10 -bits_and_bytes
Logic, shift and rotate instruction
Logic, shift and rotate instruction
Hemanth143
8086-instruction-set-ppt
computer system architecture for control system.ppt
Exp 7.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Chapter 2 Part2 A
Lecture 04 Logical Group of Instructions
Lecture no 15
Instruction 4.pptx
Chapter 2
Conditional Processing Boolean and Comparison Instructions-converted.pptx
Microprocessors-based systems (under graduate course) Lecture 4 of 9
Topic 6 - Programming in Assembly Language_230517_115118.pdf
Al2ed chapter9
POLITEKNIK MALAYSIA
Instruction set
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Big Data Technologies - Introduction.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
Programs and apps: productivity, graphics, security and other tools
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
Digital-Transformation-Roadmap-for-Companies.pptx
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Ad

Computer Organization & Assembly Language Logic Instructions

  • 1. Computer Organization & Assembly Language Logic Instructions
  • 2. Logic Instructions  To manipulate individual bits  Binary Value 0 treated as false  Binary Value 1 treated as true  In Assembly Language:  AND  OR  XOR  NOT  TEST 2
  • 3. Truth Tables 3 a b a AND b a OR b a XOR b 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 a NOT a 0 1 1 0
  • 4. Examples 1. 1010 1010 AND 1111 0000 = 1010 0000 2. 1010 1010 OR 1111 0000 = 1111 1010 3. 1010 1010 XOR 1111 0000 = 0101 1010 4. NOT 1010 1010 = 0101 0101 4
  • 5. Syntax AND destination, source OR destination, source XOR destination, source  Destination:  Stores result  Can be Register or Memory Location  Source:  May be a Constant, Register or Memory Location 5
  • 6. Effects on Flags  SF, ZF, PF reflects the result  AF is undefined  CF, OF = 0 6
  • 7. MASK  To modify only selective bits in destination, we construct a source bit pattern known as MASK.  To choose mask, use following properties:  b AND 1 = b  b AND 0 = 0  b OR 1 = 1  b OR 0 = b  b XOR 0 = b  b XOR 1 = ~b (complement of b) Where b represents a bit (0 or 1) 7
  • 8. MASK  To choose mask, use following properties:  b AND 1 = b  b AND 0 = 0  b OR 1 = 1  b OR 0 = b  b XOR 0 = b  b XOR 1 = ~b (complement of b) Where b represents a bit (0 or 1) 8
  • 9. MASK  To choose mask, use following properties:  b AND 1 = b  b AND 0 = 0  b OR 1 = 1  b OR 0 = b  b XOR 0 = b  b XOR 1 = ~b (complement of b) Where b represents a bit (0 or 1) 9
  • 10. MASK  To choose mask, use following properties:  b AND 1 = b  b AND 0 = 0  b OR 1 = 1  b OR 0 = b  b XOR 0 = b  b XOR 1 = ~b (complement of b) Where b represents a bit (0 or 1) 10
  • 11. MASK  To choose mask, use following properties:  b AND 1 = b  b AND 0 = 0  b OR 1 = 1  b OR 0 = b  b XOR 0 = b  b XOR 1 = ~b (complement of b) Where b represents a bit (0 or 1) 11
  • 12. MASK  To choose mask, use following properties:  b AND 1 = b  b AND 0 = 0  b OR 1 = 1  b OR 0 = b  b XOR 0 = b  b XOR 1 = ~b (complement of b) Where b represents a bit (0 or 1) 12
  • 13. MASK  To choose mask, use following properties:  b AND 1 = b  b AND 0 = 0  b OR 1 = 1  b OR 0 = b  b XOR 0 = b  b XOR 1 = ~b (complement of b) Where b represents a bit (0 or 1) 13
  • 14. Contd.. 1. The AND instruction: - May be used to clear specific destination bits while preventing the others. - A 0 mask bit clears the corresponding destination bit. - A 1 mask bit preserves the corresponding destination bit. 14
  • 15. Example 1  Clear the sign bit of AL while leaving the other bits unchanged.  Solution: AND AL, 7Fh Where 7Fh (0111 1111) is the mask. Suppose: AL = 0D4h Binary: 1101 0100 → AND 1101 0100 0111 1111 = 0101 0100 54h → 15
  • 16. Contd.. 2. The OR instruction: - May be used to set specific destination bits while preventing the others. - A 1 mask bit sets the corresponding destination bit. - A 0 mask bit preserves the corresponding destination bit. 16
  • 17. Example 2  Set the MSB and LSB of AL while preserving the other bits.  Solution: OR AL, 81h Where 81h (1000 0001) is the mask. Let AL = 42h Binary: 0100 0010 → OR AL, 81h OR 0100 0010 → 1000 0001 = 1100 0011 C3h → 17
  • 18. Contd.. 3. The XOR instruction: - May be used to complement specific destination bits while preventing the others. - A 1 mask bit complements the corresponding destination bit. - A 0 mask bit preserves the corresponding destination bit. 18
  • 19. Example 3  Change the sign bit of DX.  Solution: XOR DX, 8000h Where 80h (1000 0000) is the mask. DX = 7230h 0111 0010 0011 0000 → XOR 0111 0010 0011 0000 1000 0000 0000 0000 = 1111 0010 0011 0000 F230h → 19
  • 20. Nibbles  A nibble is a unit of data in computing that consists of four bits. A bit is the smallest unit of data in a computer and can have a value of either 0 or 1. A nibble, being four bits, can represent 16 different values (2^4 = 16), ranging from 0000 to 1111 in binary notation.  Four bits that are at the higher-order positions within a byte (or word). In a byte, which is typically composed of eight bits, the high nibble consists of the four bits at positions 4-7 (counting from right to left, where the rightmost bit is bit 0). 20
  • 21. Nibbles contd…  For example, consider the byte 1010 1101 in binary notation. In this byte:  The high nibble is 1010, corresponding to bits 4-7.  The low nibble is 1101, corresponding to bits 0-3. 21
  • 22. Converting an ASCII digit to a Number  ASCII code for digit “0-9” is “30h-39h” AND AL, 0Fh ;Clears the high nibble.  How to convert decimal digit to ASCII code?  Add 48 to every decimal digit.  E.g. to convert 213 into ASCII code, just add 48 to 2 then 48 to 1 and lastly 48 to three  So we get 50 49 51 22
  • 23. 23
  • 24. Lowercase to Uppercase letter  Lower case: 61h to 7Ah ( 97 to 122)  Uppercase: 41h to 5Ah (65 to 90) 24
  • 25. Clearing a Register MOV AX, 0 ;machine code 3 bytes OR SUB AX, AX ;machine code 2 bytes OR XOR AX, AX ;machine code 2 bytes 25
  • 26. Testing a Register for zero CMP CX, 0 Is same like: OR CX, CX ;sets ZF = 1 if CX is 0 26
  • 27. NOT Instruction  Performs the one’s complement operation on the destination.  Syntax: NOT destination  No effect on flags  Example: Complement the bit in AX: NOT AX 27
  • 28. TEST Instruction  Performs an AND operation without changing destination i.e. only status flags updated.  Syntax: TEST destination, source MOV AL, F0h ; AL = 1111 0000 TEST AL, 0Fh ; = 0000 1111 28
  • 29. TEST Instruction  Performs an AND operation without changing destination i.e. only status flags updated.  Syntax: TEST destination, source  Effects on flags:  SF, ZF and PF reflects the results  AF is undefined  CF, OF = 0 29