Professional Documents
Culture Documents
Microprocessors 1: The 8051 Instruction Set
Microprocessors 1: The 8051 Instruction Set
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
Instruction Groups
Arithmetic
Logic
Data Transfer
Boolean
Branching
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
Arithmetic Instructions
ADD
8-bit addition between the accumulator (A) and a
second operand.
The result is always in the accumulator.
The CY flag is set/reset appropriately.
ADDC
8-bit addition between the accumulator, a second
operand and the previous value of the CY flag.
Useful for 16-bit addition in two steps.
The CY flag is set/reset appropriately.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
C
A, 44H
A, CAH
R1, A
A, 1EH
A, 56H
R2, A
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
Arithmetic Instructions
DA
Decimal adjust the accumulator.
Format the accumulator into a proper 2 digit packed BCD
number.
Operates only on the accumulator.
Works only after the ADD instruction.
SUBB
Subtract with Borrow.
Subtract an operand and the previous value of the borrow
(carry) flag from the accumulator.
A A - <operand> - CY.
The result is always saved in the accumulator.
The CY flag is set/reset appropriately.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
C
A, #34H
A, #49H
DA
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
Arithmetic Instructions
INC
Increment the operand by one.
The operand can be a register, a direct address, an indirect
address, the data pointer.
DEC
Decrement the operand by one.
The operand can be a register, a direct address, an indirect
address.
MUL AB / DIV AB
Multiply A by B and place result in A:B.
Divide A by B and place result in A:B.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
Logical Operations
ANL / ORL
Work on byte sized operands or the CY flag.
ANL A, Rn
ANL A, direct
ANL A, @Ri
ANL A, #data
ANL direct, A
ANL direct, #data
ANL C, bit
ANL C, /bit
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
Logical Operations
XRL
Works on bytes only.
CPL / CLR
Complement / Clear.
Work on the accumulator or a bit.
CLR P1.2
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
Logical Operations
RL / RLC / RR / RRC
Rotate the accumulator.
RL and RR without the carry
RLC and RRC rotate through the carry.
SWAP A
Swap the upper and lower nibbles of the
accumulator.
No compare instruction.
Built into conditional branching instructions.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
10
MOV
8-bit data transfer for internal RAM and the SFR.
MOV A, Rn
MOV A, direct
MOV A, @Ri
MOV A, #data
MOV Rn, A
MOV Rn, direct
MOV Rn, #data
MOV direct, A
MOV direct, Rn
MOV direct, direct
MOV direct, @Ri
MOV direct, #data
MOV @Ri, A
MOV @Ri, direct
MOV @Ri, #data
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
11
MOV
1-bit data transfer involving the CY flag
MOV C, bit
MOV bit, C
MOV
16-bit data transfer involving the DPTR
MOV DPTR, #data
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
12
MOVC
Move Code Byte
Load the accumulator with a byte from program memory.
Must use indexed addressing
MOVC
MOVC
Microprocessors 1
A, @A+DPTR
A, @A+PC
Msc. Ivan A.
Escobar Broitman
13
MOVX
Data transfer between the accumulator and a byte
from external data memory.
MOVX
MOVX
MOVX
MOVX
Microprocessors 1
A, @Ri
A, @DPTR
@Ri, A
@DPTR, A
Msc. Ivan A.
Escobar Broitman
14
PUSH / POP
Push and Pop a data byte onto the stack.
The data byte is identified by a direct address from
the internal RAM locations.
PUSH
POP
Microprocessors 1
DPL
40H
Msc. Ivan A.
Escobar Broitman
15
XCH
Exchange accumulator and a byte variable
XCH A, Rn
XCH A, direct
XCH A, @Ri
XCHD
Exchange lower digit of accumulator with the lower digit of
the memory location specified.
XCHD A, @Ri
The lower 4-bits of the accumulator are exchanged with the
lower 4-bits of the internal memory location identified indirectly
by the index register.
The upper 4-bits of each are not modified.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
16
Boolean Operations
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
17
Boolean Operations
CLR
Clear a bit or the CY flag.
CLR P1.1
CLR C
SETB
Set a bit or the CY flag.
SETB A.2
SETB C
CPL
Complement a bit or the CY flag.
CPL 40H
Microprocessors 1
18
Boolean Operations
ORL / ANL
OR / AND a bit with the CY flag.
ORL C, 20H ; OR bit 20 of bit addressable
memory
with the CY flag
ANL C, /34H ; AND complement of bit 34 of bit
addressable memory with the CY
flag.
MOV
Data transfer between a bit and the CY flag.
MOV C, 3FH ; Copy the CY flag to bit 3F of the
bit addressable memory.
MOV P1.2, C ; Copy the CY flag to bit 2 of P1.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
19
Boolean Operations
JC / JNC
Jump to a relative address if CY is set / cleared.
JB / JNB
Jump to a relative address if a bit is set / cleared.
JB
ACC.2, <label>
JBC
Jump to a relative address if a bit is set and clear
the bit.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
20
Branching Instructions
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
21
Branching Instructions
Absolute Jump AJMP
Uses an 11-bit address.
2 byte instruction
The upper 3-bits of the address combine with the 5-bit
opcode to form the 1st byte and the lower 8-bits of the
address form the 2nd byte.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
22
Branching Instructions
Msc. Ivan A.
Escobar Broitman
23
Branching Instructions
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
24
Branching Instructions
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
25
Branching Instructions
Jump on Bit JB / JNB
Jump if the specified bit is set / cleared.
Any addressable bit can be specified.
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
26
Branching Instructions
CJNE
CJNE
CJNE
CJNE
Microprocessors 1
A, direct, rel
A, #data, rel
Rn, #data, rel
@Ri, #data, rel
Msc. Ivan A.
Escobar Broitman
27
Branching Instructions
Rn, rel
direct, rel
No Operation
NOP
Microprocessors 1
Msc. Ivan A.
Escobar Broitman
28