0% found this document useful (0 votes)
607 views3 pages

8051 Microcontroller Instruction Set

Uploaded by

dharani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
607 views3 pages

8051 Microcontroller Instruction Set

Uploaded by

dharani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

8051 INSTRUCTION SET

The instruction set of 8051 microcontroller can be broadly classified into the following categories:
1. Data Transfer Instructions
These instructions are used to transfer data between the registers, memory locations, or between registers and
memory. The data transfer can occur within internal memory or to/from external memory.
Common Data Transfer Instructions:
(1) MOV A, Rn: Moves the contents of register Rn to the accumulator (A).
(2) MOV A, #data: Load immediate data into the accumulator.
Eg: MOV A, #55H; Load immediate value 55H into the accumulator
(3) MOV A, direct: Moves the content of a directly addressed memory location to A.
(4) MOV Rn, A: Moves the contents of the accumulator to register Rn.
Eg: MOV R0, A; Move the content of A into register R0
(5) MOVX A, @DPTR: Moves data from external memory to accumulator using data pointer (DPTR).
(6) MOVC A, @A+DPTR: Moves code data from program memory to accumulator using DPTR as base.
2. Arithmetic Instructions
Arithmetic instructions perform mathematical operations like addition, subtraction, multiplication, division,
increment, and decrement.
Common Arithmetic Instructions:
(1) ADD A, Rn: Adds the content of register Rn to the accumulator.
Eg: ADD A, R0 ; Add the content of R0 (15H) to the accumulator (A = A + R0) ; A now contains 25H
(2) ADDC A, Rn: Add the content of register Rn to the accumulator with the carry.
Eg: ADDC A, R1 ; Add R1 + A with carry
(3) SUBB A, Rn: Subtracts the content of register Rn from the accumulator with borrow.
Eg: SUBB A, R0 ; Subtract R0 from A (A = A - R0)
(4) MUL AB: Multiplies the contents of A and B (results stored in A and B).
Eg: MUL AB ; A = 2 * 3, A = low byte and B = high byte of the result ; A = 06H, B = 00H (result is 06H)
(5) DIV AB: Divides A by B (quotient in A, remainder in B).
Eg: DIV AB ; A = A / B, result in A, remainder in B ; A = 04H (quotient), B = 00H (remainder)
(6) INC A: Increments the value in A by 1.
(7) DEC A: Decrements the value in A by 1.
3. Logical Instructions
Logical instructions perform operations like AND, OR, XOR, complement, clear, and rotate on data.
Common Logical Instructions:
(1) ANL A, Rn: Performs a bitwise AND operation between A and register Rn.
Eg: ANL A, #F0H
(2) ORL A, #data: Performs a bitwise OR operation between A and the immediate data.
Eg: ORL A, #F0H
(3) XRL A, #data: Performs a bitwise XOR operation between A and the immediate data.
Eg: XRL A, #F0H
(4) CLR A: Clears the accumulator (sets A to 0).
(5) CPL A: Complements the bits of the accumulator.
(6) RL A: Rotates the bits in A to the left.
(7) RR A: Rotates the bits in A to the right.
4. Branching Instructions
Branching instructions alter the normal sequential flow of program execution, using jumps, calls, and returns.
They enable the creation of loops and conditional statements.
Common Branching Instructions:
(1) SJMP label: Short jump to a specified address within the current 256-byte range.
(2) LJMP address: Long jump to any location in the 64KB code memory.
(3) AJMP address: Absolute jump within the same 2KB page of memory.
(4) JZ label: Jump if accumulator value is zero.
(5) JNZ label: Jump if accumulator value is not zero.
(6) CJNE A, #data, label: Compare the accumulator with an immediate value, and jump if they are not
equal.
(7) DJNZ Rn, label: Decrement register Rn and jump if the result is not zero.
5. Bit Manipulation Instructions
These instructions allow direct control over individual bits in the registers and memory locations.
Common Bit Manipulation Instructions:
(1) SETB bit: Sets the specified bit to 1.
(2) CLR bit: Clears the specified bit to 0.
(3) CPL bit: Complements the specified bit.
(4) ANL C, bit: Performs a logical AND operation between the carry and a bit.
(5) MOV C, bit: Moves the value of a bit to the carry flag.
6. Control Instructions
Control instructions manage program execution, including setting the operation mode, enabling/disabling
interrupts, and calling subroutines.
Common Control Instructions:
(1) NOP: No operation (used as a delay or place-holder).
(2) RET: Returns from a subroutine.
(3) RETI: Returns from an interrupt service routine.
(4) CALL address: Calls a subroutine at the specified address.
(5) ACALL address: Calls a subroutine within the same 2KB page.
(6) LCALL address: Calls a subroutine anywhere in the 64KB memory.

8051 PROGRAMMING EXAMPLE: LED BLINKING


Let's create a simple program to toggle an LED connected to Port 1, pin 0 using a delay loop.
ORG 0000H ; Start program from address 0
MAIN: MOV P1, #00H ; Set all pins of Port 1 to low (LED OFF)
ACALL DELAY ; Call delay subroutine
MOV P1, #01H ; Set bit 0 of Port 1 to high (LED ON)
ACALL DELAY ; Call delay subroutine
SJMP MAIN ; Jump back to MAIN and repeat

DELAY: MOV R1, #255 ; Load register R1 with maximum value


DLOOP1: MOV R2, #255 ; Load register R2 with maximum value
DLOOP2: DJNZ R2, DLOOP2 ; Decrement R2 until it reaches zero
DJNZ R1, DLOOP1 ; Decrement R1 and repeat inner loop
RET ; Return from subroutine
Explanation:
 The program toggles the LED by writing to Port 1.
 A delay subroutine is used to create a visible delay between LED state changes.
 The loop continues indefinitely, blinking the LED on and off.

You might also like