Instruction Format 8051
Instruction Format 8051
Instruction Format 8051
INSTRUCTION = command to the microcontroller Consists of op-code and operand Word size: one byte => includes the opcode and operand in the same byte
INSTRUCTION FORMAT
Data types and directives: DB => Define Byte => used to define data format 8051 supports decimal, hexadecimal, ASCII, and binary data Decimal D ASCII Binary B Eg: ADD A, #50 ; D is optional Eg: MOV A, #A Eg: MOV A, #01010000B
INSTRUCTION FORMAT
Data types and directives: ORG ORIGIN Used to indicate the beginning of address
EQU EQUATE
Used to define constant without occupying a memory location Associates a constant value with a data label Wherever the label occurs the constant value is sustituted COUNT EQU 25 MOV R3, #COUNT
The 16-bit register DPTR and register A are used to form the
address of the data element stored in on-chip ROM.
register DPTR to form the 16- bit address of the needed data.
Logic Instructions
Bit-oriented Instructions
Arithmetic Instructions
ADD A,Rn Adds the register to the accumulator ADD A,direct Adds the direct byte to the accumulator ADD A,@Ri ADD A,#data ADDC A,Rn Adds the indirect RAM to the accumulator Adds the immediate data to the accumulator Adds the register to the accumulator with a carry flag
ADDC A,direct Adds the direct byte to the accumulator with a carry flag ADDC A,@Ri Adds the indirect RAM to the accumulator with a carry flag ADDC A,#data Adds the immediate data to the accumulator with a carry flag
Arithmetic Instructions
SUBB A,Rn Subtracts the register from the accumulator with a borrow
SUBB A,direct Subtracts the direct byte from the accumulator with a borrow SUBB A,@Ri Subtracts the indirect RAM from the accumulator with a borrow Subtracts the immediate data from the accumulator with a SUBB A,#data borrow INC A INC Rn INC Rx INC @Ri Increments the accumulator by 1 Increments the register by 1 Increments the direct byte by 1 Increments the indirect RAM by 1
Arithmetic Instructions
DEC A DEC Rn DEC Rx Decrements the accumulator by 1 Decrements the register by 1 Decrements the direct byte by 1
DEC @Ri
INC DPTR MUL AB DIV AB DA A
BRANCHING INSTRUCTIONS
ACALL addr11 Absolute subroutine call LCALL addr16 Long subroutine call RET Returns from subroutine
RETI
AJMP addr11 LJMP addr16 SJMP rel
BRANCHING INSTRUCTIONS
JC rel JNC rel
JB bit,rel JBC bit,rel JMP @A+DPTR JZ rel JNZ rel
Jump if carry flag is set. Short jump. Jump if carry flag is not set. Short jump.
Jump if direct bit is set. Short jump. Jump if direct bit is set and clears bit. Short jump. Jump indirect relative to the DPTR Jump if the accumulator is zero. Short jump. Jump if the accumulator is not zero. Short jump.
BRANCHING INSTRUCTIONS
CJNE A,direct,rel CJNE A,#data,rel CJNE Rn,#data,rel CJNE @Ri,#data,rel DJNZ Rn,rel DJNZ Rx,rel NOP Compares direct byte to the accumulator and jumps if not equal. Short jump. Compares immediate data to the accumulator and jumps if not equal. Short jump.
Compares immediate data to the register and jumps if not equal. Short jump.
Compares immediate data to indirect register and jumps if not equal. Short jump. Decrements register and jumps if not 0. Short jump. Decrements direct byte and jump if not 0. Short jump. No operation
DATA TRANSFER
MOV A,Rn MOV A,direct MOV A,@Ri MOV A,#data Moves the register to the accumulator Moves the direct byte to the accumulator Moves the indirect RAM to the accumulator Moves the immediate data to the accumulator
MOV Rn,A
MOV Rn,direct Moves the direct byte to the register MOV Rn,#data Moves the immediate data to the register MOV direct,A Moves the accumulator to the direct byte
DATA TRANSFER
MOV direct,A MOV direct,Rn MOV direct,@Ri MOV @Ri,A Moves the accumulator to the direct byte Moves the register to the direct byte Moves the indirect RAM to the direct byte Moves the accumulator to the indirect RAM MOV direct,direct Moves the direct byte to the direct byte MOV direct,#data Moves the immediate data to the direct byte
Moves the direct byte to the indirect RAM Moves the immediate data to the indirect RAM
Moves the code byte relative to the DPTR to the accumulator (address=A+DPTR)
DATA TRANSFER
Moves the external RAM (8-bit address) to the accumulator Moves the external RAM (16-bit address) to the MOVX A,@DPTR accumulator Moves the accumulator to the external RAM (8-bit MOVX @Ri,A address) Moves the accumulator to the external RAM (16-bit MOVX @DPTR,A address) PUSH direct Pushes the direct byte onto the stack POP direct Pops the direct byte from the stack/td> XCH A,Rn Exchanges the register with the accumulator XCH A,direct Exchanges the direct byte with the accumulator XCH A,@Ri Exchanges the indirect RAM with the accumulator Exchanges the low-order nibble indirect RAM with the XCHD A,@Ri accumulator MOVX A,@Ri
LOGICAL INSTRUCTIONS
ANL A,Rn ANL A,direct ANL A,@Ri ANL A,#data ANL direct,A ANL direct,#data ORL A,Rn ORL A,direct ORL A,@Ri ORL direct,A ORL direct,#data AND register to accumulator AND direct byte to accumulator AND indirect RAM to accumulator AND immediate data to accumulator AND accumulator to direct byte AND immediae data to direct register OR register to accumulator OR direct byte to accumulator OR indirect RAM to accumulator OR accumulator to direct byte OR immediate data to direct byte
LOGICAL INSTRUCTIONS
XRL A,Rn XRL A,direct Exclusive OR register to accumulator Exclusive OR direct byte to accumulator
XRL A,@Ri
XRL A,#data XRL direct,A CLR A
CPL A
SWAP A RL A RLC A RR A
RRC A
ORL C,/bit
MOV C,bit MOV bit,C