Logical Operations

It is always desired to have a compact program without compromising the quick response of the system.

Data and SFRs of 8051 microcontroller may be manipulated by byte opcodes.

There exist an area in internal RAM that is bit addressable and also some of the SFRs may be manipulated byte-wise as well as bit-wise.

What it means to be bit-addressable is that, it is possible to be operate on the individual bit level of the entire byte.

Copy the following program into your Keil program and look for the changes in result step-by-step.

/* This program gives the demonstration of byte level as well as bit level Logical Operations.*/

// Byte level Logical Operations

MOV A,#0FFH;
MOV B,#55H;
MOV R0,#06FH;
MOV R1,#38H;
MOV 38H,#08AH;

// AND Logic
// Instruction format is ANL destination, source
// result is stored in destination.
// that means destination = destination AND source

ANL A,#89H;
ANL A,B;
ANL A,R0;
ANL A,@R1;

// OR Logic
// Instruction format is ORL destination, source
// result is stored in destination.
// that means destination = destination OR source

ORL A,#89H;
ORL 0F0H,0E0H;
ORL A,R0;
ORL A,@R1;

// XOR Logic
// Instruction format is XRL destination, source
// result is stored in destination.
// that means destination = destination XOR source

XRL A,#89H;
XRL 0F0H,0E0H;
XRL A,R0;
XRL A,@R1;

END

For above program, look for the result in Registers and SFRs. Note that after executing each of these instructions , there is no change in PSW and the results are stored in “destination”. Also, these instructions can be used with all four types of addressing modes.

Please, refer bit addressable Internal RAM and SFRs from 8051 Architecture and/or Logical Operations Instructions from this link before going further.

/* This program gives the demonstration of byte level as well as bit level Logical Operations.*/

// Bit level Logical Operations

SETB 00H;
SETB 7FH;
SETB 33H;
CPL 33H;
CPL C;
MOV C,33H;
MOV 01H,C;
CLR 33H;
SETB C;

// AND Logic
// Instruction format is ANL destination, source
// result is stored in destination.
// that means destination = destination AND source

ANL C,00H;
ANL C,33H;
ANL C,7FH;
ANL C,/7FH;
ANL C,/00H;

// OR Logic
// Instruction format is ORL destination, source
// result is stored in destination.
// that means destination = destination OR source

ORL C,00H;
ORL C,33H;
ORL C,7FH;
ORL C,/7FH;
ORL C,/00H;

// Logical Operations with some of the Bit Addressable Registers
SETB 0E0H; //Register A bit 1
SETB 0E1H; //Register A bit 2
SETB 0E7H; //Register A bit 8
SETB 0F0h; //Register B bit 0
SETB 0F5H; //Register B bit 6
SETB 0F3H; //Register B bit 4
SETB 80h; //Register Port 0 bit 1
SETB 85H; //Register Port 0 bit 6
CLR 85H; //Register Port 0 bit 6
SETB 93H; //Register Port 1 bit 4
CLR 93H; //Register Port 1 bit 4
SETB 0A2H; //Register Port 2 bit 3
CLR 0A2H; //Register Port 2 bit 3
SETB 0A7H; //Register Port 2 bit 8
CLR 0A7H; //Register Port 2 bit 8


END

For above program, look for the result in Registers 20H to 2FH and only bit addressable SFRs.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s