0% found this document useful (0 votes)
178 views39 pages

Module - 2: 8051 Instruction Set

This document provides an overview of the 8051 instruction set including addressing modes, data transfer instructions, arithmetic instructions, logical instructions, branch instructions, and bit manipulation instructions. It also provides examples of assembly language programs that utilize MOV, PUSH, POP, XCH, arithmetic, logical, rotate, boolean, and other instructions. The examples demonstrate how to transfer and exchange data between memory locations using various instructions.

Uploaded by

Pramod Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views39 pages

Module - 2: 8051 Instruction Set

This document provides an overview of the 8051 instruction set including addressing modes, data transfer instructions, arithmetic instructions, logical instructions, branch instructions, and bit manipulation instructions. It also provides examples of assembly language programs that utilize MOV, PUSH, POP, XCH, arithmetic, logical, rotate, boolean, and other instructions. The examples demonstrate how to transfer and exchange data between memory locations using various instructions.

Uploaded by

Pramod Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Module -2

8051 Instruction Set:


Topics to be covered
• Addressing Modes,
• Data Transfer instructions
• Arithmetic instructions
• Logical instructions
• Branch instructions
• Bit manipulation instructions.
• Simple Assembly language program examples
(without loops) to use these instructions.
Addressing Modes
1.Immediate AM
• Source operand is constant and the data must
e appended by # sign
2.Register AM
• This AM uses the registers to hold the source
& destination contents.
3.Direct AM
• Address of the data is available directly as a
part of instruction.
4.Register Indirect AM
• Register is used to hold the address of the data using @
symbol.
• R0 & R1 are only registers which can hold the 8bit address
for external access(16bit)DPTR is used.
5.Indexed AM
• It is used widely in accessing data elements of
lookup table in the program ROM space.
Data Transfer Instructions
• The different instructions of this group are
– MOV
– PUSH
– POP
– XCH
MOV instruction
• Copies the data source to destination
– Syntax
– MOV dst,src MOVX,MOVC
EX- 1.MOV A,Rn----------(1B,1C)
2.MOV A,direct------(2B,1C)
3.MOV A,@R0---------(1B,1C)
4.MOV A,#data-------(2B,1C)
5.MOV Rn,A-----------(1B,1C)
6.MOV Rn,direct -----(2B,2C)
7.MOV Rn,#data-----(2B,1C)
8.MOV direct,A------(2B,1C)
9.MOV direct,direct-(3B,2C)
10.MOV direct,@Ri---(2B,2C)
11.MOV @Ri,direct--- (2B,1C)
12.MOV c,bit------------ (2B,1C)--------Ex-MOV c,P1.4
13,MOV bit,c------------ (2B,2C) -------Ex-MOV P1.4,c
PUSH & POP instructions
• PUSH direct address
– SP incremented by 1(SP=07h08h)
– Data pushed on to stack m/m
• POP direct address
– Data popped from stack m/m
– SP decremented by 1(SP=08h07h)
XCH (Exchange) instruction
1.XCH A,Rn----(1B,1C)
2.XCH A,direct----(2B,1C)
3.XCH A,@Ri----(1B,1C)
4.XCHD A,@Ri----(1B,1C)(exchange Digit/Lower nibble)

A=54 Ri 60 60->46


Arithmetic Instructions
1.SUB/ADD A,Rn----(1B,1C)
2.SUB/ADD A,direct----(2B,1C)
3.SUB/ADD A,@Ri----(1B,1C)
4. SUB/ADD A,#data----(2B,1C)
5. SUBB/ADDC A,Rn----(1B,1C)
6. SUBB/ADDC A,direct----(2B,1C)
7. SUBB/ADDC A,@Ri----(1B,1C)
8. SUBB/ADDC A,#data----(2B,1C)
Multiplication
• MUL AB---(1B,4C)
(A X B)->B(higher byte) A(Lower byte)
Ex- A=50h,B=A0h
after execution
50 XA0=3200h
B=32h A=00h
Division
Unsigned division
DIV AB-----(1B,4C)
A/B----- A=result ,B=reminder
Ex—
A=35h,B=10h
DIV AB
A=3h,B=5h
Increment & Decrement Operation
1.DEC/INC A----(1B,1C)
2. DEC/INC Rn----(1B,1C)
3. DEC/INC direct----(2B,1C)
4. DEC/INC @Ri----(1B,1C)
5. INC DPTR----(1B,2C)
DAA
• Decimal Adjust Accumulator after addition
This instruction used to convert the obtained
result to BCD after the addition of 2 BCD
numbers
DAA examples
Logical Instruction
ANL dst,src---Bitwise Logical ANDing
1.ANL A,Rn----(1B,1C) - no flags affected
2.ANL A,70h---(1B,1C)
3.ANL A,@R1----(1B,1C)
4.ANL direct,A----(2B,1C)
Ex-ANL P1,#01111111B (P1.7 masked)
5. ANL C,bit------(2B,2C) - cy flags affected
6. ANL c,|bit------(2B,2C)
SWAP
• SWAP A--------(1B,1C)
Swaps lower nibble with higher nibble
Logical OR operation
ORL dst,src
1. ORL A,Rn----(1B,1C)
2.ORL A,70h---(1B,1C)---No flags affected
3.ORL A,@Ri---(1B,1C)
4.ORL A,#data---(2B,1C)
5.ORL direct,A---(2B,1C)
6.ORL direct,#data---(3B,2C)
7.ORL c,bit---(2B,2C)--- cy flags affected
8.ORL c,|bit---(2B,2C)--cy flags affected
Logical XOR
1.XRL A,Rn----(1B,1C) - no flags affected
2.XRL A,direct----(2B,1C)
3.XRL A,@Ri----(1B,1C)
4.XRL A,#data----(2B,1C)
5.XRL direct,A----(2B,1C)
6.XRL direct,#data----(3B,2C)
7.XRL A,Rn----(1B,1C)
Rotate Instructions
1.RL A--(1B,1C) - no flags affected
2.RR A--(1B,1C) - no flags affected
3.RLC A--(1B,1C) - Cy flags affected
3.RRC A--(1B,1C) - Cy flag affected
NOP- -(1B,1C) ---No operation

• This instruction performs no operation &


execution continues with next instruction
• It Only updates PC content
Boolean Instructions
1 CLR bit-(1B,1C)-----------Clear bit
2.CPL bit-(2B,1C)----Complement bit
3.CPL C---(1B,1C)----Complement carry bit
4.SETB C ---(1B,1C)----Set carry bit

Ex-SETB C

5.SETB bit ---(2B,1C)----Set a bit


Ex-SETB P1.0
SETB P4.6
5.CLR A----(1B,1C)
Clears the accumulator content
Ex-MOV A,#055h
CLR A
A=00H
6.CPL A----(1B,1C)
Complements the accumulator content
Ex-MOV A,#0FFh
CPL A
A=00H
Write an assembly language program to transfer n = 10 bytes of data
from location 8035H to location 8050H (without overlap).
ORG 0000H
SJMP 30H
ORG 30H
MOV DPH, #80H
MOV R0, #35H //source address
MOV R1, #50H //destination address
MOV R3, #0AH //count
BACK: MOV DPL, r0 //get data from source
MOVX A, @dptr
MOV DPL, R1
MOVX @dptr,A //move to destination
INC R0 //increment pointers
INC R1
DJNZ R3, BACK
HERE: SJMP HERE //wait here
END
• Result:
• Before Execution: 10 locations X:8035H are filled up with data.

After Execution: 10 locations X:8050H are filled up with data from


8035H.
Write an assembly language program to exchange n = 5
bytes of data at location 0027H and at location 0041H.
ORG 0000H
SJMP 30H
ORG 30H
MOV R0, #27H //source1 address
MOV R1, #41H // source2 address
MOV R3, #05H //count
BACK: MOVX A, @r0 //get data from source
MOV r2, A //save it in R2
MOVX A, @r1 //get data from destination
MOVX @r0, A //move it to source
MOV A, r2 //move source data (stored in R2)
MOVX @r1, A //to destination
INC R0 //increment pointers
INC R1
DJNZ R3, BACK //decrement count and repeat
HERE: SJMP HERE //wait here
END
RESULT:
Before Execution: 5 locations at X:0027H & X:0041H are filled up
with data.

After Execution: The data at X:0027H & X:0041H are exchanged.

You might also like