Logical Instructions of 8051 Microcontroller | AND | OR | XOR | CPL | SWAP | Instructions of 8051

Engineering Funda
18 Aug 202209:26

Summary

TLDRThis educational video delves into the logical instructions of the microcontroller 8051, focusing on operations such as AND, OR, XOR, complement, and swap. The instructor provides syntax and examples for each instruction, demonstrating how they can be applied with the accumulator, direct data, and internal RAM addresses. Additionally, the video covers special operations like CPL for NOT, and NOP for delay, offering a comprehensive guide for those looking to understand or program with the 8051 microcontroller.

Takeaways

  • πŸ˜€ The video is part of a lecture series on the microcontroller 8051, focusing on logical instructions.
  • πŸ” It covers various logical operations including AND, OR, XOR, and complement/swap instructions.
  • πŸ“˜ The 'AND' operation is performed using the 'ANL' instruction, which can be between the accumulator and a register, direct data, or a memory location.
  • πŸ”„ The 'OR' operation is executed with the 'ORL' instruction, similarly involving the accumulator and different data sources.
  • πŸ”’ The 'XOR' operation is done using 'XRL', which also compares the accumulator with various data types and locations.
  • πŸ” The 'CPL' instruction is used to perform the NOT operation, which can be combined with other operations to form NAND, NOR, and XNOR.
  • ❌ The 'CLR' instruction clears the accumulator, setting it to 0x00.
  • πŸ”„ The 'SWAP' instruction swaps the lower and higher nibbles of the accumulator.
  • πŸ•’ The 'NOP' (No Operation) instruction is used to generate a delay without performing any operation.
  • πŸ“ The video provides examples for each instruction to help understand their application in programming.
  • πŸ‘¨β€πŸ« The instructor encourages students to ask questions in the comment box for further clarification.

Q & A

  • What is the purpose of the video lecture series on the microcontroller 8051?

    -The purpose of the video lecture series is to explain the logical instructions of the microcontroller 8051, providing examples to help viewers understand how to use these instructions in programming.

  • What are the types of logical instructions covered in the video?

    -The video covers logical AND (ANL), logical OR (ORL), logical XOR (XRL), complement (CPL), swap (SWAP), and no operation (NOP) instructions.

  • What does the ANL instruction do in the 8051 microcontroller?

    -The ANL instruction performs a logical AND operation between two eight-bit numbers and stores the result in the accumulator A.

  • Can you provide an example of how to use the ANL instruction with direct data?

    -An example of using ANL with direct data is 'ANL A, #50H', which performs a logical AND operation between the accumulator A and the value 50H, storing the result in A.

  • How does the ORL instruction differ from the ANL instruction?

    -The ORL instruction performs a logical OR operation between two eight-bit numbers instead of an AND operation, and the result is stored in the accumulator A.

  • What is the syntax for the ORL instruction when using it with a memory location?

    -The syntax for the ORL instruction with a memory location is 'ORL A, @R1', where R1 points to a memory location in internal RAM, and the data at that location is logically ORed with A.

  • What does the XRL instruction perform, and how is it different from ANL and ORL?

    -The XRL instruction performs a logical XOR operation between two eight-bit numbers. Unlike ANL and ORL, which perform AND and OR operations respectively, XRL results in a value that has bits set to 1 only where the two operands have different bits.

  • Can you explain the CPL instruction and its use in logical operations?

    -The CPL instruction performs a NOT operation on the accumulator A, inverting all its bits. It can be used in combination with other logical instructions to achieve NAND, NOR, and XNOR operations.

  • What is the function of the SWAP instruction in the 8051 microcontroller?

    -The SWAP instruction is used to swap the lower nibble and the higher nibble of the accumulator A, effectively reversing the order of the four bits in each nibble.

  • What does the NOP instruction do, and why might it be used in programming?

    -The NOP (No Operation) instruction does not perform any operation. It is used to generate a delay or to align timing in the program execution without affecting the processor state.

  • How can the CLR instruction be used in programming with the 8051 microcontroller?

    -The CLR instruction is used to clear the accumulator A, setting it to 00H. This can be useful for resetting the accumulator to a known state before further operations.

Outlines

00:00

πŸ€– Introduction to 8051 Microcontroller Logical Instructions

This paragraph introduces the video lecture series on the 8051 microcontroller, focusing on logical instructions. The instructor promises to explain various logical operations such as AND, OR, XOR, complement, and swap, using examples to clarify their application in programming. The explanation includes how to perform these operations between the accumulator and various data sources like direct data, internal RAM addresses, and register contents. The paragraph sets the stage for a detailed exploration of logical instructions in the 8051 microcontroller.

05:03

πŸ” Deep Dive into 8051 Logical Operations and Special Instructions

The second paragraph delves deeper into the specifics of logical operations in the 8051 microcontroller, including the syntax and application of AND, OR, and XOR operations with accumulator, registers, and memory locations. It also introduces the CPL (complement) and SWAP (swap nibbles) instructions, explaining how they can be used to create additional logical operations like NAND, NOR, and XNOR. The paragraph concludes with the explanation of the CLR (clear accumulator) and NOP (no operation) instructions, emphasizing their unique roles in programming. The summary highlights the comprehensive coverage of logical instructions and their practical implications in microcontroller programming.

Mindmap

Keywords

πŸ’‘Microcontroller 8051

The Microcontroller 8051 is a specific type of microcontroller that was popular in the 1980s and is still used for its simplicity and cost-effectiveness in various applications. In the context of the video, it is the central topic as the instructor explains various logical instructions associated with programming the 8051 microcontroller. The script mentions it in the introduction, setting the stage for the detailed discussion of its logical operations.

πŸ’‘Logical Instructions

Logical instructions are a set of commands used in programming to perform logical operations such as AND, OR, XOR, and NOT on binary data. The video focuses on explaining these operations in the context of the 8051 microcontroller, showing how they are fundamental to microcontroller programming and digital logic.

πŸ’‘AND Operation

The AND operation is a fundamental logical operation that results in a true output (1) only when both operands are true (1). In the video, the AND operation is demonstrated with the 'ANL' instruction, which is used to perform a logical AND between the accumulator and a specified operand, with the result stored in the accumulator.

πŸ’‘OR Operation

The OR operation is another basic logical operation that yields a true output (1) if at least one of the operands is true (1). The video script uses 'ORL' to illustrate how the OR operation is performed in the 8051 microcontroller, showing examples of using it with different types of operands.

πŸ’‘XOR Operation

The XOR (exclusive OR) operation is a logical operation that outputs true (1) if the operands are different. The video explains the 'XRL' instruction for performing the XOR operation in the 8051, highlighting its use with immediate data, registers, and memory locations.

πŸ’‘Complement

Complement refers to the logical NOT operation, which inverts the bits of a binary number. In the script, 'CPL' is the instruction used to perform the complement operation on the accumulator, flipping all its bits from 0 to 1 and vice versa.

πŸ’‘Swap

The 'swap' instruction is used to exchange the high and low nibbles of the accumulator in the 8051 microcontroller. The video explains this as a way to easily manipulate the data within the accumulator without changing its overall value.

πŸ’‘NOP Operation

NOP stands for 'No Operation' and is an instruction that does not perform any operation but is used to create a delay or align timing in a program. The video mentions NOP as an example of an instruction that does not alter the state of the microcontroller but can be useful for timing purposes.

πŸ’‘Accumulator

The accumulator in a microcontroller like the 8051 is a register used for arithmetic and logical operations. The video frequently refers to the accumulator as the destination for the results of logical operations, emphasizing its central role in microcontroller operations.

πŸ’‘Internal RAM

Internal RAM refers to the memory within the microcontroller used for storing data and program instructions. The video script explains how logical instructions can operate not only with the accumulator but also with data stored in internal RAM, using memory addresses to specify the location.

πŸ’‘Instruction Syntax

Instruction syntax refers to the format and structure of the commands used in programming. The video script provides examples of the syntax for various logical instructions, such as 'ANL A, #50H', which demonstrates how to write and understand the command structure for performing logical operations in the 8051 microcontroller.

Highlights

Introduction to the microcontroller 8051 and its logical instructions.

Explanation of logic AND operation with syntax 'ANL' between two eight-bit numbers.

Demonstration of logic AND operation using accumulator, register, and direct data.

Use of internal RAM addresses with logic AND operation.

Clarification on the difference between direct data and memory location in logic AND operations.

Introduction to logic OR operation with syntax 'ORL'.

Examples of logic OR operation with accumulator, register, and memory location.

Explanation of logic XOR operation with syntax 'XRL'.

Illustration of logic XOR with accumulator, register, and internal RAM location.

Use of CPL instruction for NOT operation on accumulator.

Application of CPL for achieving NAND, NOR, and XNOR operations.

Description of CLR instruction for clearing the accumulator.

Explanation of the SWAP instruction for swapping nibbles within the accumulator.

Introduction of the NOP instruction for generating delay without performing any operation.

Emphasis on the importance of understanding logical instructions for programming with 8051.

Invitation for viewers to ask questions and seek clarification in the comments section.

Transcripts

play00:00

welcome to engineering Funda family this

play00:02

video is a part of microcontroller 8051

play00:05

video lecture series and in this video

play00:06

I'll be going to explain you all the

play00:08

logical instructions of microcontroller

play00:10

8051 with 8051 we have logic and logic

play00:14

or logic xor as well as complement and

play00:17

swap instructions I'll explain you all

play00:19

the instructions along with example so

play00:21

that you will be having fair enough idea

play00:23

about how we can use all these

play00:24

instructions in programming let us see

play00:26

all those instructions one by one along

play00:28

with examples so Here My Dear students

play00:31

I'll explain you first how logic and

play00:33

instructions are there with 8051

play00:36

for logic and operation syntax is a and

play00:40

l

play00:41

it will perform logic and operation in

play00:44

between two eight bits numbers

play00:46

let me explain you this by for some

play00:48

examples like when you write a and L

play00:51

then a comma has 50 H what you do is you

play00:56

perform logic and operation of a with

play00:59

Phi 0 h

play01:01

and answer will get stored inside

play01:03

accumulator a

play01:05

when you execute a and l a comma R1 then

play01:09

you will be performing logic and

play01:11

operation in between a and R1 and answer

play01:14

will get stored inside a

play01:17

when you execute a and l a comma 1 7 H

play01:21

at the time here You observe my dear

play01:24

students you are not writing hash

play01:26

here you are writing hash what it means

play01:28

50 H is getting ended with a n answer

play01:31

was getting stored inside a here we are

play01:34

not writing hash what it means this 1 7

play01:37

H is memory location with internal Ram

play01:42

so at that location whatever data is

play01:45

there that we are ending with a and

play01:47

answer is getting stored inside a

play01:50

when you execute a and l a comma at the

play01:54

rate R1 what you do is here at the rate

play01:57

R1 means here R1 is pointing RAM memory

play02:01

location

play02:02

and at that location whatever data is

play02:05

that that is getting logic ended with a

play02:07

and answer is getting stored inside a

play02:10

so Here My Dear students you should know

play02:12

how to use internal Ram here by directly

play02:16

writing address of internal Ram we can

play02:19

perform this ANL as well as by using

play02:22

resistor as well we can have usage of

play02:25

internal Ram in which you will have to

play02:26

use at the rate symbol

play02:29

now my dear students if you execute A

play02:31

and L 2 Phi H comma a in that case you

play02:35

see here you are performing logic and

play02:38

operation of a with internal Rams memory

play02:42

location 25 hex

play02:44

and that is getting stored inside

play02:48

25 hex internal memory location

play02:51

so when you have 2 Phi H directly

play02:54

written in instruction what it means

play02:56

this is internal Rams memory location at

play02:59

that location whatever data is there

play03:00

that you are doing in terms of logic and

play03:03

width accumulator a and here first I am

play03:07

writing 2 Phi H what it means at this

play03:09

location only we need to store our

play03:11

answer

play03:13

my dear students when you execute A and

play03:16

L 2 Phi H comma has 50 h

play03:19

so in that case you will be performing

play03:21

logic and operation of 50 H with memory

play03:25

location pointed by 2 Phi H in internal

play03:28

RAM and answer is getting stored at 2

play03:32

Phi H internal Rams memory location

play03:35

when we talk about logic or operations

play03:38

for that my dear students basic syntax

play03:41

is o r l

play03:43

here you will be performing two bits

play03:47

numbers logic or operation

play03:49

for example when you write orl a comma 5

play03:52

0 H in that case Phi zero is getting

play03:56

logic or with accumulator an answer is

play03:58

getting stored inside a

play04:01

R1 will perform logic or operation of a

play04:04

with R1 and answer is getting stored

play04:06

inside a

play04:07

when you execute orl a comma 1 7 as here

play04:10

we are not writing hash what it means

play04:12

this is my memory location in internal

play04:15

Ram

play04:15

so at this location whatever data is

play04:17

there that is getting logic or with a

play04:19

and answer is getting stored in a

play04:21

when you execute Orla comma at the rate

play04:24

R1 at that time R1 is pointing internal

play04:28

srams address

play04:29

and at that address whatever data is

play04:31

there that is getting logic or with a an

play04:33

answer is getting stored inside a

play04:35

here also my dear students when you

play04:37

write orl

play04:39

a 25 H comma a then here 25 H that is

play04:44

Rams internals memory location

play04:46

and at that location whatever data is

play04:49

there that is getting logic or with a

play04:51

and answer is getting stored at this

play04:53

location right

play04:55

when you execute orl 25 H comma hash 50

play04:59

H in that case immediately this 50h data

play05:02

is getting logic or with the memory

play05:04

location pointed by 25 h

play05:06

in internal memory location of Ram and

play05:09

answer is getting stored over here

play05:11

so Here My Dear students logic and and

play05:14

logic are operation that we can perform

play05:16

as per accumulator with resistor

play05:19

accumulator with direct data accumulator

play05:21

with Rams address accumulator with data

play05:24

pointed by resistor inside internal Ram

play05:26

right so that is how we can use this now

play05:29

my dear students I'll explain you logic

play05:31

xor instructions

play05:33

here for logic xor you should know

play05:36

syntax is xrl that will perform logic

play05:40

xor operation in between two eight bits

play05:42

numbers

play05:43

let me give you some examples for

play05:45

example when you execute xrl a comma

play05:48

hash 50 H what it means you will be

play05:50

performing logic xor operation of 50h

play05:54

with accumulator and answer is getting

play05:56

stored inside a

play05:58

when you execute xrl a comma R1 you'll

play06:01

be performing logic xor operation of a

play06:04

and R1 and answer is getting stored

play06:06

inside a when you execute xrl a comma 1

play06:09

7 x what you do is here you see we are

play06:13

not writing hash what it means this is

play06:15

internal Rams memory location so 1 7

play06:18

hacks that is internal Rams memory

play06:20

location at that location whatever data

play06:22

is there that is getting xor with a and

play06:25

answer is getting stored inside a when

play06:27

you execute xrl a comma at the rate R1

play06:29

at the rate means now R1 is pointing

play06:32

memory location inside internal Ram

play06:35

so at that location whatever data is

play06:37

there that you will be xoring with a and

play06:40

answer is getting stored inside a when

play06:42

you execute xrl 2 Phi H comma a what you

play06:46

do is you perform xor operation of a

play06:49

with internal Rams location 25 hex and

play06:52

answer is getting stored over here at

play06:54

internal Rams address 2 Phi H hex

play06:58

Here My Dear students when you execute

play07:00

xrl 2 Phi H comma has 50 H what you do

play07:04

is you perform logic xor operation of

play07:06

data pointed by memory location 25 hex

play07:10

with 50 hex and your answer is getting

play07:13

stored inside internal Rams address at

play07:16

25h so that is how logic xor

play07:19

instructions are available now my dear

play07:22

students I'll explain you some other

play07:25

logical instructions like CPL so CPL a

play07:29

that performs not operation right so you

play07:33

see once complement of a that is getting

play07:35

performed once complement means what

play07:37

logic not operation so CPL can be used

play07:40

to have some other logical operations

play07:43

how you see we have logic and logic R

play07:47

and logic xor so to make an end after

play07:50

and if you have CPL it will make it to

play07:53

nand

play07:54

after or if you use CPL it will make it

play07:57

to nor and after xor if you execute CPL

play08:01

means it will make it to X Norm that is

play08:04

how all the logic operation that we can

play08:06

have in 8051

play08:09

when you execute CLR what you do is you

play08:12

will be clearing accumulator means after

play08:15

execution of this accumulator will

play08:17

become 0 0 h

play08:19

when you execute swap instruction

play08:22

my dear students here swap a that is

play08:25

used to swap lower nibble and higher

play08:27

nibble of accumulator

play08:29

so here as if you have a is equals to 7

play08:33

8 H after instruction execution

play08:36

a will become

play08:38

eight seven so you see lowering and

play08:40

upper nibble that we are swapping over

play08:42

here right

play08:44

Here My Dear students at last no

play08:47

operation instruction is there n o p so

play08:50

this instruction does not do anything

play08:52

that is just used to generate delay

play08:54

right so it will not perform any

play08:57

operation NOP

play08:59

so my dear students this is how logical

play09:02

instructions are there with eight zero

play09:03

five one in which here you should know

play09:06

for nand nor and xnor after this

play09:12

instruction you will have to use CPL to

play09:15

have other logical operation as well so

play09:18

this is how all the logical instructions

play09:20

are there still if any confusion is

play09:22

there just post that in comment box I'll

play09:23

be happy to help you thank you so much

play09:25

for watching this video

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Microcontroller8051Logical InstructionsProgrammingLogic ANDLogic ORLogic XORComplementSwapCPLNOP