0% found this document useful (0 votes)
2 views

Module-2

Uploaded by

anu.spamm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module-2

Uploaded by

anu.spamm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Department of Electronics and Computer Science

TE(EXCS) SEM-V
Microcontroller & Applications
By
Dr. Arun Chavan

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Assembly Language Programming

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Addressing Modes

Addressing Modes of 8051:

Addressing modes can be defined as different ways of specifying operands


in the instruction.

In 8051 There are six types of addressing modes.


• Immediate Addressing Mode
• Register Addressing Mode
• Direct Addressing Mode
• Register Indirect Addressing Mode
• Indexed Addressing Mode
• Implied Addressing Mode
Dr. Arun Chavan, Department of Electronics and Computer Science
8051 Addressing Modes
Addressing Modes of 8051:
Immediate Addressing mode
In this Addressing Mode, the data is provided in the instruction itself. The
data is provided immediately after the opcode. These are some examples of
Immediate Addressing Mode.

MOV A,#0FH;
MOV R3,#45H;
MOV DPTR,#2E00H;

Register Addressing mode


In the register addressing mode the source or destination data should be
present in a register (R0 to R7). These are some examples of Register
Addressing Mode.

MOV A,R5;
MOV R2,R1;
MOV R0,A; Dr. Arun Chavan, Department of Electronics and Computer Science
8051 Addressing Modes
Addressing Modes of 8051:
Direct Addressing Mode
In the Direct Addressing Mode, the source or destination in the instruction
specifies 8-bit direct address of the operand. The internal data memory and
SFRs can be addressed directly. Here some of the examples of direct
Addressing Mode.

MOV 80H,R6;
MOV R2,45H;

Register Indirect Addressing Mode


In this mode, the source or destination address is given in the register. By
using register indirect addressing mode, the internal or external memory
can be accessed. The R0 and R1 are used for 8-bit addresses, and DPTR is
used for 16-bit addresses.

MOVX A,@DPTR;
Dr. Arun Chavan, Department of Electronics and Computer Science
MOV @R1, A
8051 Addressing Modes
Addressing Modes of 8051:

Indexed Addressing mode


In the indexed addressing mode, the source memory can only be program
memory. The destination operand is always the register A. The address is
generated as some base plus index.

MOVC A,@A+PC;
MOVC A,@A+DPTR;

Implied Addressing Mode


In the implied addressing mode, the operands are included in the opcode
itself. These types of instruction can work on specific registers only. These
types of instructions are also known as register specific instruction.

RL A;
SWAP A;
Dr. Arun Chavan, Department of Electronics and Computer Science
8051 Addressing Modes
Quiz

1. The instruction MOV A,#20H comes under


a. Reg. Addr. b. Immediate Addr. c. Reg. Indirect Addr.
2. The instruction MOVC A, @A+DPTR comes under
a. Reg. Addr. , b. Index Addr. , c. Immediate Addr.
3. In which addressing mode operands & address of the operand are
fixed
a. Implied Addr. b. Direct Addr. c. Immediate Addr.
4. Addressing modes are different ways of specifying operands in the
Instruction
a. True b. False
5. Special character used for indirect addressing is
a. $ b. # c. @
Dr. Arun Chavan, Department of Electronics and Computer Science
8051 Assembler Directives

What is Assembler Directive ?

• Assembler directive is a statement/reserved-key-word to give


direction to the assembler to perform task of
the assembly process.
• They indicate how an operand, or a section of the program is to be
processed by the assembler
• It controls the organization of the program and provide necessary
information to the assembler to understand the assembly
language programs to generate necessary machine codes
• An assembler supports directives to define data, to organise
segments to control procedure, to define subroutine/macros.
Dr. Arun Chavan, Department of Electronics and Computer Science
8051 Assembler Directives
DB Define Byte

DW Define a byte type (8-bit) variable

DD Reserves specific amount of memory locations to each


variable
DQ

DT
Example:

ORG
LIST DB 7FH, 42H, 35H
END

EQU
Three consecutive byte memory locations are
reserved for the variable LIST and each 8-bit data
specified in the statement is stored as initial value in
the reserved memory location

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Assembler Directives
DB
Define Word
DW
Define a word type (16-bit) variable
DD
Reserves two consecutive byte memory locations to
DQ each variable

DT
Example:
ORG

END ALIST DW 6512H, 7251H, 4DE2H

EQU

Three consecutive word memory locations are


reserved for the variable ALIST and each 16-bit data
specified in the statement is stored in three
consecutive memory location.

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Assembler Directives
DB
Define Double word
DW
Define a double word type (32-bit) variable
DD
Reserves four consecutive byte memory locations to
DQ each variable

DT
Example:
ORG

END Num DD 11226512H, 87877251H, 35454DE2H

EQU

Three consecutive double word memory locations are


reserved for the variable Num and each 32-bit data
specified in the statement is stored in three
consecutive memory location.

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Assembler Directives
DB
Define Quad word
DW
Define a quad word type (64-bit) variable
DD
Reserves eight consecutive byte memory locations to
DQ each variable

DT
Example:
ORG

END Num DQ 234511226512H

EQU

A 64 bit, quad word memory locations is reserved for


the variable Num

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Assembler Directives
DB
Define Ten bytes
DW
Define a Ten Byte type (80-bit) variable
DD
Reserves ten consecutive byte memory locations to
DQ each variable

DT
Example:
ORG

END Num DT ?

EQU

Ten consecutive byte memory locations are reserved


for the variable Num

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Assembler Directives
DB
ORG (Origin) is used to assign the starting address (Effective
DW address) for a program/ data in the segment

END is used to terminate a program; statements after END


DD
will be ignored

DQ
EQU (Equate) is used to attach a value to a variable
DT
For Example :
ORG
OGR 1000H
END
Two EQU 2
EQU
MOV A, R0
|
|
|
END

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Assembler Directives
Quiz

1. The assembler directive ‘DW’ reserves how many bits of memory


for the variable
a. 8 b. 16 c. 32
2. The END directive is used to terminate the program list
a. True b. False
3. ORG directive is to decide the starting address of program or
data
a. True b False
4. Assembler directives are converted into machine code by
assembler
a. True b. False
5. Assembler directives are reserved key words
a. True b. False
Dr. Arun Chavan, Department of Electronics and Computer Science
Assignment no - 2
Short Questions (2 Marks)

1. Define and Classify ‘Addressing Modes’ for 8051


2. What are ‘Assembler Directives’ ? Give any two examples.

Descriptive Questions (5 Marks)

1. Discuss addressing modes for 8051.


2. Discuss assembler directives with examples.

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Instruction Set

The instructions of 8051 Microcontroller can be classified into


five different groups. These groups are like below

• Data Transfer Group

• Arithmetic Group

• Logical Group

• Program Branch Group

• Bit Processing Group

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Instruction Set
Data Transfer Instructions
8051 Instruction Set
Data Transfer Instructions

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Instruction Set
Arithmetic Instructions
8051 Instruction Set
Logic Instructions
8051 Instruction Set
Program/Branch control
Instructions
8051 Instruction Set
Boolean variable/Bit
Processing
Instructions

Dr. Arun Chavan, Department of Electronics and Computer Science


8051 Instruction Set
Quiz
1. If A=54H, B=0FH then on the execution of ANL A,B result in A
will be
a. 50H b. 04H c. 0FH
2. If R0=40H, [40]=25H then on the execution of MOV A, @R0
contents of A will be
a. 40H b. 25H c. 65H
3. The instruction LJMP 16-bit address is how many byte
instruction
a. 2 b. 3 c. 4
4. The instruction CLR C comes under Bit Processing Instructions
a. True b. False
5. If A= 56H before execution of SWAP A, then what will be the
contents of A after execution
a. 56H b. 65H c. 00H
Dr. Arun Chavan, Department of Electronics and Computer Science
Assignment no - 3
Short Questions (2 Marks)

1. Explain the operation of the following instructions


a. SWAP A b. PUSH B
2. If A=FFH, B=10H then on the execution of ORL A,B what will be the result in A
3 If R1=40H, [40]=20H then on the execution of MOV A, @R0 what will the
contents of A

Descriptive Questions (5 Marks)

1. Classify the Instruction set of 8051 and give at least four examples under each group of
instructions.
2. Write assembly language program for 8051 to subtract contents of external RAM 5001H
from the contents of 5000H and store result at 6000H and borrow at 6001H.
3. Write assembly language program for 8051 to count +ve and -ve elements of an array of 10
elements stored in the internal RAM from 50H onwards, store the +ve element count in R4
& -ve element count in R5.

Dr. Arun Chavan, Department of Electronics and Computer Science


Thank You !

Dr. Arun Chavan, Department of Electronics and Computer Science

You might also like