0% found this document useful (0 votes)
55 views34 pages

Instruction Set of

The document summarizes the instruction set of the 8051 microcontroller. It groups the instructions into 5 categories: 1) arithmetic, 2) logic, 3) data transfer, 4) boolean, and 5) branching. The arithmetic instructions include ADD, SUBB, INC, DEC, MUL, and DIV. The logic instructions perform AND, OR, XOR operations. Data transfer instructions like MOV, MOVX are used to move data. Boolean instructions set, clear, and complement bits. Branching instructions provide conditional and unconditional jumps and calls to control program flow.
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)
55 views34 pages

Instruction Set of

The document summarizes the instruction set of the 8051 microcontroller. It groups the instructions into 5 categories: 1) arithmetic, 2) logic, 3) data transfer, 4) boolean, and 5) branching. The arithmetic instructions include ADD, SUBB, INC, DEC, MUL, and DIV. The logic instructions perform AND, OR, XOR operations. Data transfer instructions like MOV, MOVX are used to move data. Boolean instructions set, clear, and complement bits. Branching instructions provide conditional and unconditional jumps and calls to control program flow.
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/ 34

INSTRUCTION

SET OF
8051

486
8051 Instruction
Set
• The instructions are grouped into 5 groups
– Arithmetic
– Logic
– Data Transfer
– Boolean
– Branching

2
1. Arithmetic Instructions
• ADD
– 8-bit addition between the accumulator (A) and a
second operand.
• The result is always in the accumulator.
• The C Y flag is set/reset appropriately.

• ADDC
– 8-bit addition between the accumulator, a second
operand and the previous value of the C Y flag.

3
ADD Instruction
• ADD A, source ;ADD the source operand
to
the
• M O V A, #03H ;load 03H into A
M O V B,#02H ;load 02accumulator
H into B

ADD A,B ;add B register to accumulator


;(A = A + B)= 05

4
SUBB
–Subtract with Borrow.
– A  A - <operand> - CY.
–The result is always saved in the
accumulator.
–The C Y flag is set/reset
appropriately.

5
SUBB Instruction
• SUBB A, source ;ADD the source operand
to
the
• M O V A, #03H ;load 03H into A
M O V B,#02H accumulator
;load 02H into B
SUBB A,B ;add B register to accumulator
;(A = A - B)= 01

6
• INC
– Increment the operand by one. Ex: I N C
DPTR
• The operand can be a register, a direct address,
an indirect address, the data pointer.

• D EC
– Decrement the operand by one. Ex: D EC B
• The operand can be a register, a direct address,
an indirect address.

• M U L A B / D IV A B
– Multiply A by B and place result in A:B.
– Divide A by B and place result in A:B.
7
Multiplication of Numbers
MUL AB ; A  B, place 16-bit result in B and A
M O V A,#05 ;load 05H to reg. A
M O V B,#03 ;load 03H in reg. B
M U L AB ;05 * 03 = 000F where B = 00 and A =
0F

Table 6-1:Unsigned Multiplication Summary (MUL AB)

Multiplication Operand 1 Operand 2 Result

byte byte A B A=low byte,


B=high
byte

8
Multiplication Concept
MUL AB ; A  B, place 16-bit result in B and A

MOV A,#25H ;load 25H to reg. A


MOV B,#65H ;load 65H in reg. B
MUL AB ;25H * 65H = E99 where B = 0EH and A = 99H

Table 6-1:Unsigned Multiplication Summary (MUL AB)

Multiplication Operand 1 Operand 2 Result

byte  byte A B A=low byte,


B=high
byte

9
Division of Numbers
M O V A,#05 ;load 05H to reg. A
M O V B,#03 ;load 03H in reg. B
DIV AB ;05/03 =>Quotient = 01,Reminder = 02

where B = 02 and A =
01
Table 6-2:Unsigned Division Summary (DIV
AB)
Division Numerator Denominator Quotient Remainder
byte / byte A B A B

10
Division Concept
DIV AB ; divide A by B

• MOV ;load 95 into A


A,#95H ;load 10 into B
• MOV ;now A = 09 (quotient) and B = 05 (remainder)
B,#10H
• DIV AB
Table 6-2:Unsigned Division Summary (DIV
AB)
Division Numerator Denominator Quotient Remainder
byte / byte A B A B

11
• A D D A,@Rn A = A + memory pointed to
Rn
• DA Decimal Adjust A {BCD addition}

•AA D D C A,@Rn
• SUBB A,@Rn
• I N C @Ri

12
2. Logical
instructions

13
• ANL D,S
-Performs logical A N D of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: A N L A,#0FH A N L A,R5
• ORL D,S
-Performs logical OR of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: ORL A,#28H ORL A,@R0

14
• XRL D,S
-Performs logical XOR of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: XRL A,#28H XRL A,@R0
• CPL A
-Compliment accumulator
-gives 1’s compliment of accumulator data
• SWAP A
-Exchange the upper & lower nibbles of accumulator

15
• RL A
-Rotate data of accumulator towards left
without carry
• RLC A
- Rotate data of accumulator towards left with carry
• RR A
-Rotate data of accumulator towards right
without carry
• RRC A
- Rotate data of accumulator towards right
with carry

16
3. Data Transfer
Instructions

17
MOV Instruction
• MOV destination, source ; copy source to
destination.
• MOV ;load value 55H into reg. A
A ,#55H ;copy contents of A into R0
MOV R0,A ;(now A=R0=55H)
M O V R1,A ;copy contents of A into R1
;(now A=R0=R1=55H)
M O V R2,A ;copy contents of A into R2
;(now A=R0=R1=R2=55H)
M O V R3,#95H ;load value 95H into R3
;(now R3=95H)
MOV ;copy contents of R3 into A
A ,R3 ;now A=R3=95H

18
• M OV X
– Data transfer between the accumulator and
a byte from external data memory.
• MOVX A, @Ri
• MOVX A, @DPTR
• MOVX @Ri, A
• MOVX @DPTR, A

Presented by C.GOKUL,AP/EEE , Velalar College of Engg & Tech, Erode 502


• PUSH / POP
– Push and Pop a data byte onto the stack.
– The data byte is identified by a direct
address from the internal R A M locations.

• PUSH DPL
• POP 40H

20
• XC H
– Exchange accumulator and a byte variable
• XC H A, Rn
• XC H A, direct
• XC H A, @Ri

21
4. Boolean Variable
Instructions

22
C LR:
• The operation clears the specified bit indicated in
the instruction
• Ex: CLR C clear the carry
SETB:
• The operation sets the specified bit to 1.

CPL:
• The operation complements the specified bit
indicated in the instruction

23
• ANL C,<Source-bit>

-Performs A N D bit addressed with the carry bit.


- Eg: A N L C ,P2.7 A N D carry flag with bit 7
of P2

• ORL C,<Source-bit>

-Performs OR bit addressed with the carry bit.


- Eg: ORL C ,P2.1 OR carry flag with bit 1 of
P2
24
• XORL C,<Source-
bit>
-Performs XOR bit addressed with the carry bit.
- Eg: XO L C ,P2.1 O R carry flag with bit 1 of
P2

• MOV
P2.3,C
• MOV
C ,P3.3
• MOV
25
5. Branching
instructions

26
• Program branching instructions are
used to control the flow of actions in
a program

Some instructions provide
decision making capabilities and
transfer control to other parts of the
program.
– e.g. conditional and
unconditional branches
27
Jump Instructions
• All conditional jumps are short jumps
– Target address within -128 to +127 of PC

• LJMP (long jump): 3-byte instruction


– 2-byte target address: 0000 to FFFF H
– Original 8051 has only 4KB on-chip
RO M

• SJMP (short jump): 2-byte instruction


– 1-byte relative address: -128 to +127
28
Call Instructions
• LC A L L (long call): 3-byte instruction
– 2-byte address
– Target address within 64K-byte range

• A C A L L (absolute call): 2-byte instruction


– 11-bit address
– Target address within 2K-byte range

29
• The 8051 provides 2 forms for the
return instruction:
– Return from subroutine – RET
– Return from ISR – RETI

30
31

You might also like