Professional Documents
Culture Documents
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
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
8
Multiplication Concept
MUL AB ; A B, place 16-bit result in B and A
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
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
• 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>
• ORL C,<Source-bit>
• 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
29
• The 8051 provides 2 forms for the
return instruction:
– Return from subroutine – RET
– Return from ISR – RETI
30
31