0% found this document useful (0 votes)
1 views

Instruction_set_of_Microcontroller_8051-1-9 (1)

The document outlines the instruction set for the 8051 microcontroller, detailing various categories of instructions including data transfer, arithmetic, logical, jump, call, and bit-wise instructions. Each instruction is described with its operation, syntax, and functionality, providing examples for clarity. This comprehensive guide serves as a reference for programming the 8051 microcontroller effectively.

Uploaded by

isaacsabu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Instruction_set_of_Microcontroller_8051-1-9 (1)

The document outlines the instruction set for the 8051 microcontroller, detailing various categories of instructions including data transfer, arithmetic, logical, jump, call, and bit-wise instructions. Each instruction is described with its operation, syntax, and functionality, providing examples for clarity. This comprehensive guide serves as a reference for programming the 8051 microcontroller effectively.

Uploaded by

isaacsabu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Instruction set of Microcontroller 8051

Data Transfer Instructions

Operation: MOV
Syntax: MOV destination, source

MOV R0, addr


MOV addr,R0

Description: MOV copies the value of source into destination. The value of source is
not affected. Both destination and source must be in Internal RAM. No flags are
affected unless the instruction is moving the value of a bit into the carry bit in which
case the carry bit is affected or unless the instruction is moving a value into the PSW
register (which contains all the program flags).
Ex:
MOV A,R2
MOV R2,#data

Operation: MOVX
Function: Move Data To/From External Memory (XRAM)
Syntax: MOVX operand1,operand2

Description: MOVX moves a byte to or from External Memory into or from the
Accumulator.

Ex:
MOVX A,@DPTR
MOVX @DPTR,A

If operand1 is @DPTR, the Accumulator is moved to the 16-bit External Memory


address indicated by DPTR. If operand2 is DPTR then the byte is moved from External
Memory into the Accumulator.
Operation: SWAP
Function: Swap Accumulator Nibbles
Syntax: SWAP A

Description: SWAP swaps bits 0-3 of the Accumulator with bits 4-7 of the
Accumulator. This instruction is identical to executing "RR A" or "RL A" four times.

Operation: XCH
Function: Exchange Bytes
Syntax: XCH A,register

Description: Exchanges the value of the Accumulator with the value contained in
register.
Ex: XCH A, R1

Operation: PUSH
Function: Push Value Onto Stack
Syntax: PUSH

Description: PUSH "pushes" the value of the specified address onto the stack.

Operation: POP
Function: Pop Value From Stack
Syntax: POP

Description: POP "pops" the last value placed on the stack into the address specified.

Arithmetic Instructions

Operation: ADD, ADDC


Function: Add Accumulator, Add Accumulator With Carry

Description: Description: ADD and ADDC both add the value operand to the value
of the Accumulator, leaving the resulting value in the Accumulator. ADD and ADDC
function identically except that ADDC addsthe value of operand as well as the value of
the Carry flag whereas ADD does not add the Carry flag to the result.
Operation: SUBB
Function: Subtract from Accumulator With Borrow

Description: SUBB subtract the value of operand from the value of the Accumulator,
leaving the resulting value in the Accumulator. The value operand is not affected.

The Carry Bit (C) is set if a borrow was required for bit 7, otherwise it is cleared.

Operation: MUL
Function: Multiply Accumulator by B
Syntax: MUL AB

Description: Multiples the unsigned value of the Accumulator by the unsigned value
of the "B" register. The least significant byte of the result is placed in the Accumulator
and the most-significant-byte is placed in the "B" register.

The Carry Flag (C) is always cleared.

Operation: DIV
Function: Divide Accumulator by B
Syntax: DIV AB

Description: Divides the unsigned value of the Accumulator by the unsigned value of
the "B" register. The resulting quotient is placed in the Accumulator and the remainder
is placed in the "B" register.

The Carry flag (C) is always cleared.

Operation: INC
Function: Increment Register
Syntax: INC register

Description: INC increments the value of register by 1.

Operation: DEC
Function: Decrement Register
Syntax: DEC register

Description: DEC decrements the value of register by 1.


Logical Instructions

Operation: ORL
Function: Bitwise OR
Syntax: ORL operand1,operand2

Description: ORL does a bitwise "OR" operation between operand1 and operand2,
leaving the resulting value in operand1.

Operation: ANL
Function: Bitwise AND
Syntax: ANL operand1, operand2

Description: ANL does a bitwise "AND" operation between operand1 and operand2,
leaving the resulting value in operand1.

Operation: XRL
Function: Bitwise Exclusive OR
Syntax: XRL operand1,operand2

Description: XRL does a bitwise "X-OR" operation between operand1 and operand2,
leaving the resulting value in operand1.

Operation: CPL
Function: Complement Register
Syntax: CPL operand
Description: CPL complements operand, leaving the result in operand. If operand is
a single bit then the state of the bit will be reversed. If operand is the Accumulator
then all the bits in the Accumulator will be reversed.

Operation: CLR
Function: Clear Register
Syntax: CLR register

Description: CLR clears (sets to 0) all the bit(s) of the indicated register. If the register
is a bit (including the carry bit), only the specified bit is affected. Clearing the
Accumulator sets the Accumulator's value to 0.
Operation: RL
Function: Rotate Accumulator Left
Syntax: RL A

Description: Shifts the bits of the Accumulator to the left. The left-most bit (bit 7) of
the Accumulator is loaded into bit 0.

Operation: RR
Function: Rotate Accumulator Right
Syntax: RR A

Description: Shifts the bits of the Accumulator to the right. The right-most bit (bit 0)
of the Accumulator is loaded into bit 7.

Operation: RLC
Function: Rotate Accumulator Left Through Carry
Syntax: RLC A

Description: Shifts the bits of the Accumulator to the left. The left-most bit (bit 7) of
the Accumulator is loaded into the Carry Flag, and the original Carry Flag is loaded
into bit 0 of the Accumulator.

Operation: RRC
Function: Rotate Accumulator Right Through Carry
Syntax: RRC A

Description: Shifts the bits of the Accumulator to the right. The right-most bit (bit 0)
of the Accumulator is loaded into the Carry Flag, and the original Carry Flag is loaded
into bit 7.
Jump Instructions

Unconditional Jump
The unconditional jump is a jump in which control is transferred unconditionally to the
target location.

Operation: SJMP
Function: Short Jump
Syntax: SJMP reladdr (8 bit address)

Description: Short Jump unconditionally to the 8 bit address (relative) indicated. The
relative address ranges from 00H to FF.

Relative address must be within -128 or +127 bytes of the instruction that follows the SJMP
instruction.

Operation: LJMP
Function: Long Jump
Syntax: LJMP 16 bit address

Description: LJMP causes an unconditional branch to the indicated 16 bit address .The
2-byte target address is to allow a jump to any memory location from 0000 to FFFF.

Operation: JMP
Function: Jump to address pointed by Accumulator + Data Pointer
Syntax: JMP @A+DPTR

Description: JMP jumps unconditionally to the address represented by the sum of the
value of DPTR and the value of the Accumulator.

Operation: AJMP

Function: Absolute Jump Within 2K Block


Syntax: AJMP 11 bit address
Description: AJMP unconditionally jumps to the indicated code address.

Conditional Jump
The conditional jump is a jump in which control is transferred to the target location
only if a specified condition is met. All conditional jumps are short jump.

Operation: JC
Function: Jump if Carry Set
Syntax: JC reladdr

Description: JC will branch to the address indicated by reladdr if the Carry Bit is set.
If the Carry Bit is not set program execution continues with the instruction following
the JC instruction.

Operation: JNC
Function: Jump if Carry Not Set
Syntax: JNC reladdr

Description: JNC branches to the address indicated by reladdr if the carry bit is not
set. If the carry bit is set program execution continues with the instruction following the
JNB instruction.

Operation: JZ

Function: Jump if Accumulator Zero


Syntax: JZ reladdr

Description: JZ branches to the address indicated by reladdr if the Accumulator


contains the value 0. If the value of the Accumulator is non-zero program execution
continues with the instruction following the JNZ instruction.

Operation: JNZ
Function: Jump if Accumulator Not Zero
Syntax: JNZ reladdr

Description: JNZ will branch to the address indicated by reladdr if the Accumulator
contains any value except 0. If the value of the Accumulator is zero program execution
continues with the instruction following the JNZ instruction.

Operation: DJNZ
Function: Decrement and Jump if Not Zero
Syntax: DJNZ register , reladdr

Description: DJNZ decrements the value of register by 1. If the new value of register
is not 0 the program will branch to the address indicated by relative addr. If the new
value of register is 0 program flow continues with the instruction following the DJNZ
instruction.
Call instructions
CALL is used to call a subroutine or function. Subroutines are used to perform operations
or tasks that need to be performed frequently. This makes a program more structured and
saves memory space. There are two instructions − LCALL and ACALL.

Operation: LCALL
Syntax: LCALL 16_bit_address
Function: Long Call to any address Within full range of memory,

Description: This instruction is used to call a subroutine at any memory address within
the 8051's code memory.

Operation: ACALL
Function: Absolute Call Within 2K Block
Syntax: ACALL 11_bit_address

Description: This instruction also calls a subroutine but is more limited in range, within
2K memory block only.

Operation: RET
Function: Return From Subroutine
Syntax: RET

Description: RET is used to return from a subroutine previously called by LCALL or


ACALL. Program execution continues at the address that is calculated by popping the
topmost 2 bytes off the stack. The most-significant-byte is popped off the stack first,
followed by the least-significant-byte.

Bit-Wise Instructions (Single-Bit level instructions)

Operation: JB
Function: Jump if Bit Set
Syntax: JB bit addr, reladdr
Description: JB branches to the address indicated by reladdr if the bit indicated by
bit addr is set. If the bit is not set program execution continues with the instruction
following the JB instruction.

Operation: JNB
Function: Jump if Bit Not Set
Syntax: JNB bit addr,reladdr

Description: JNB will branch to the address indicated by reladdress if the indicated bit
is not set. If the bit is set program execution continues with the instructionfollowing the
JNB instruction.

Operation: JBC
Function: Jump if Bit Set and Clear Bit
Syntax: JB bit addr, reladdr

Description: JBC will branch to the address indicated by reladdr if the bit indicated by
bit addr is set. Before branching to reladdr the instruction will clear the indicated bit.
If the bit is not set program execution continues with the instruction following the JBC
instruction

You might also like