0% found this document useful (0 votes)
96 views7 pages

Explanation of The Following 8051 Instructions With Examples

The document explains various 8051 assembly instructions with examples, detailing their functions and results. Instructions include MOV, SUBB, XCH, RLC, ADD, and others, demonstrating operations like moving data, arithmetic calculations, and bit rotations. Each instruction is accompanied by a specific example to illustrate its usage and outcome.

Uploaded by

ashkf
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)
96 views7 pages

Explanation of The Following 8051 Instructions With Examples

The document explains various 8051 assembly instructions with examples, detailing their functions and results. Instructions include MOV, SUBB, XCH, RLC, ADD, and others, demonstrating operations like moving data, arithmetic calculations, and bit rotations. Each instruction is accompanied by a specific example to illustrate its usage and outcome.

Uploaded by

ashkf
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
You are on page 1/ 7

Explanation of the Following 8051 Instructions with Examples

(i) MOV A, #45H

Instruction: MOV A, #45H


Explanation: This instruction loads the immediate value 45H into the accumulator (A).
Example:

MOV A, #45H ; Load 45H into accumulator A

Result: A = 45H

(ii) MOVX @DPTR, A

Instruction: MOVX @DPTR, A


Explanation: This instruction moves the contents of the accumulator (A) to an external
memory location addressed by DPTR.
Example:

MOV DPTR, #3000H ; Load external memory address 3000H into DPTR
MOV A, #55H ; Load 55H into accumulator
MOVX @DPTR, A ; Store 55H at external memory address 3000H

Result: External memory location 3000H contains 55H

(iii) SUBB A, @R0

Instruction: SUBB A, @R0


Explanation: This instruction subtracts the value stored at the internal RAM address pointed
by R0 from the accumulator (A), including the borrow (CY flag).
Example:

MOV R0, #30H ; Load address 30H into R0


MOV A, #50H ; Load 50H into accumulator
MOV 30H, #20H ; Store 20H at internal RAM location 30H
SUBB A, @R0 ; A = A - (value at address in R0) - CY

Result: A = 50H - 20H = 30H (assuming no borrow)

1
(iv) XCH A, R1

Instruction: XCH A, R1
Explanation: This instruction exchanges the contents of the accumulator (A) with register R1.
Example:

MOV A, #12H ; Load 12H into A


MOV R1, #34H ; Load 34H into R1
XCH A, R1 ; Swap values of A and R1

Result: A = 34H, R1 = 12H

(v) RLC A

Instruction: RLC A
Explanation: This instruction rotates the accumulator (A) left through the carry flag (CY).
The MSB (bit 7) is moved into CY, and CY is moved into the LSB (bit 0).
Example:

MOV A, #85H ; Load 85H (10000101B) into A


SETB C ; Set carry flag (CY = 1)
RLC A ; Rotate left through carry

Before Rotation: A = 10000101B, CY = 1


After Rotation: A = 00001011B (0BH), CY = 1

(VI) XCH A, R2

 Function: This instruction exchanges the contents of the accumulator (A) with register R2.
 Example:
 MOV A, #12H ; Load 12H into A
 MOV R2, #34H ; Load 34H into R2
 XCH A, R2 ; Swap values of A and R2

Result: A = 34H, R2 = 12H

(VII) ADD A, #23

 Function: Adds the immediate value 23H to the accumulator (A) and stores the result in A.
 Example:
 MOV A, #15H ; Load 15H into A

2
 ADD A, #23H ; Add 23H to A

Result: A = 15H + 23H = 38H

(VIII) MOV DPTR, #9000H

 Function: Loads the DPTR (Data Pointer Register) with the immediate 16-bit address
(9000H). This instruction is useful when working with external memory.
 Example:
 MOV DPTR, #9000H ; Load DPTR with the address 9000H

Result: DPTR = 9000H

(IX) SUBB A, R2

 Function: Subtracts the value in register R2 from the accumulator (A), including the
borrow (CY flag).
 Example:
 MOV A, #40H ; Load 40H into accumulator
 MOV R2, #10H ; Load 10H into R2
 CLR C ; Clear carry to ensure no borrow
 SUBB A, R2 ; A = A - R2 - CY

Result: A = 40H - 10H = 30H (assuming no borrow)

(X) RRC A (Rotate Right through Carry)

 Function: Rotates the accumulator (A) right through the carry flag (CY). The LSB
(bit 0) moves into CY, and CY moves into MSB (bit 7).
 Example:
 MOV A, #8BH ; Load A with 8BH (10001011B)
 CLR C ; Clear carry flag (CY = 0)
 RRC A ; Rotate right through carry

Before Rotation: A = 10001011B, CY = 0


After Rotation: A = 01000101B (45H), CY = 1

(XI) ADD A, @R0

3
 Function: Adds the value stored at the internal RAM location pointed by register R0
to the accumulator (A).
 Example:
 MOV R0, #30H ; Load address 30H into R0
 MOV A, #25H ; Load 25H into accumulator
 MOV 30H, #15H ; Store 15H at RAM location 30H
 ADD A, @R0 ; A = A + (value at address in R0)

Result: A = 25H + 15H = 3AH

(i) ADDC A, #23

 Function: Adds the immediate value 23H to the accumulator (A) along with the carry
(CY) flag.
 Example:
 MOV A, #50H ; Load A with 50H
 SETB C ; Set carry flag (CY = 1)
 ADDC A, #23H ; A = A + 23H + CY

Result: A = 50H + 23H + 1 = 74H, CY remains unchanged if no overflow occurs.

(ii) RLC A (Rotate Left through Carry)

 Function: Rotates the accumulator (A) left through the carry flag (CY). The MSB
(bit 7) moves into CY, and CY moves into LSB (bit 0).
 Example:
 MOV A, #85H ; Load A with 85H (10000101B)
 CLR C ; Clear carry flag (CY = 0)
 RLC A ; Rotate left through carry

Before Rotation: A = 10000101B, CY = 0


After Rotation: A = 00001010B (0AH), CY = 1

(iii) XCH A, R1

 Function: Exchanges the contents of the accumulator (A) with register R1.
 Example:
 MOV A, #12H ; Load A with 12H
 MOV R1, #34H ; Load R1 with 34H
 XCH A, R1 ; Swap values of A and R1

Result: A = 34H, R1 = 12H

4
5
(b) Comparison of Instruction Pairs

(i) MOV 10H, 20H vs. MOV 20H, #20

Instruction Function

Copies the contents of memory location 20H into memory location 10H. (Indirect
MOV 10H, 20H
move)

MOV 20H, #20 Loads the immediate value 20H into memory location 20H.

Example:

MOV 20H, #55H ; Store 55H at memory location 20H


MOV 10H, 20H ; Copy value at 20H (55H) to 10H

Result: Memory 10H = 55H

(ii) MOV R1, A vs. MOV @R1, A

Instruction Function

MOV R1, A Copies the value from accumulator (A) to register R1.

MOV @R1, A Stores the value of accumulator (A) at the internal RAM address pointed by R1.

Example:

MOV A, #44H ; Load 44H into A


MOV R1, #30H ; Load 30H into R1
MOV @R1, A ; Store A’s value (44H) at RAM location 30H

Result: RAM location 30H contains 44H

6
(i) MOV 15H, 20H vs. MOV 15H, #20H

Instruction Function
Copies the contents of memory location 20H into memory location 15H.
MOV 15H, 20H
(Indirect move)
MOV 15H,
Loads the immediate value 20H into memory location 15H.
#20H

Example:

MOV 20H, #55H ; Store 55H at memory location 20H


MOV 15H, 20H ; Copy value at 20H (55H) to 15H

Result: Memory 15H = 55H

(ii) MOV R1, A vs. MOV @R1, A

Instruction Function
MOV R1, A Copies the value from accumulator (A) to register R1.
Stores the value of accumulator (A) at the internal RAM address pointed by
MOV @R1, A
R1.

Example:

MOV A, #44H ; Load 44H into A


MOV R1, #30H ; Load 30H into R1
MOV @R1, A ; Store A’s value (44H) at RAM location 30H

Result: RAM location 30H contains 44H

You might also like