filmov
tv
How to Use ADD instruction in 8051 Microcontroller : Add data into Microcontroller
Показать описание
#ADD_instruction
#8051microxontroller
#Add_instruction_in_8051Microntroller
In the 8051 microcontroller, the ADD instruction is used to add the contents of a register or a direct byte to the accumulator (A register). The result of the addition is stored in the accumulator. Here are the different formats of the ADD instruction:
Add Immediate: Adds an immediate data byte to the accumulator.
assembly
Copy code
ADD A, #data
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
ADD A, #0x03 ; Add 0x03 to accumulator (A = A + 0x03)
Add Direct: Adds the content of a direct address to the accumulator.
assembly
Copy code
ADD A, direct
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
MOV 30H, #0x03 ; Load 0x03 into address 30H
ADD A, 30H ; Add content of address 30H to accumulator (A = A + content of 30H)
Add Register: Adds the content of a register (R0-R7) to the accumulator.
assembly
Copy code
ADD A, Rn
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
MOV R1, #0x03 ; Load 0x03 into register R1
ADD A, R1 ; Add content of R1 to accumulator (A = A + R1)
Add Indirect: Adds the content of the memory location pointed to by a register (R0 or R1) to the accumulator.
assembly
Copy code
ADD A, @Ri
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
MOV R0, #30H ; Load address 30H into R0
MOV 30H, #0x03 ; Load 0x03 into address 30H
ADD A, @R0 ; Add content of address pointed by R0 to accumulator (A = A + content of 30H)
Steps to Add Data into 8051 Microcontroller:
Load the accumulator with the initial value:
assembly
Copy code
MOV A, #initial_value
Add immediate data to the accumulator (if using immediate data):
assembly
Copy code
ADD A, #data
Add data from a direct address (if using direct addressing):
assembly
Copy code
MOV direct_address, #data
ADD A, direct_address
Add data from a register (if using register addressing):
assembly
Copy code
MOV Rn, #data
ADD A, Rn
Add data from an indirect address (if using indirect addressing):
assembly
Copy code
MOV Ri, #address
MOV address, #data
ADD A, @Ri
Example Program:
Suppose we want to add the numbers 0x05 and 0x03 and store the result in the accumulator.
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into the accumulator
ADD A, #0x03 ; Add 0x03 to the accumulator
; The result (0x08) is now in the accumulator
This program will load 0x05 into the accumulator and then add 0x03 to it, resulting in 0x08 in the accumulator.
Remember to handle potential overflow if the result exceeds the 8-bit limit (255 or 0xFF). The carry flag (CY) in the Program Status Word (PSW) will be set if there is an overflow.
#8051microxontroller
#Add_instruction_in_8051Microntroller
In the 8051 microcontroller, the ADD instruction is used to add the contents of a register or a direct byte to the accumulator (A register). The result of the addition is stored in the accumulator. Here are the different formats of the ADD instruction:
Add Immediate: Adds an immediate data byte to the accumulator.
assembly
Copy code
ADD A, #data
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
ADD A, #0x03 ; Add 0x03 to accumulator (A = A + 0x03)
Add Direct: Adds the content of a direct address to the accumulator.
assembly
Copy code
ADD A, direct
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
MOV 30H, #0x03 ; Load 0x03 into address 30H
ADD A, 30H ; Add content of address 30H to accumulator (A = A + content of 30H)
Add Register: Adds the content of a register (R0-R7) to the accumulator.
assembly
Copy code
ADD A, Rn
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
MOV R1, #0x03 ; Load 0x03 into register R1
ADD A, R1 ; Add content of R1 to accumulator (A = A + R1)
Add Indirect: Adds the content of the memory location pointed to by a register (R0 or R1) to the accumulator.
assembly
Copy code
ADD A, @Ri
Example:
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into accumulator
MOV R0, #30H ; Load address 30H into R0
MOV 30H, #0x03 ; Load 0x03 into address 30H
ADD A, @R0 ; Add content of address pointed by R0 to accumulator (A = A + content of 30H)
Steps to Add Data into 8051 Microcontroller:
Load the accumulator with the initial value:
assembly
Copy code
MOV A, #initial_value
Add immediate data to the accumulator (if using immediate data):
assembly
Copy code
ADD A, #data
Add data from a direct address (if using direct addressing):
assembly
Copy code
MOV direct_address, #data
ADD A, direct_address
Add data from a register (if using register addressing):
assembly
Copy code
MOV Rn, #data
ADD A, Rn
Add data from an indirect address (if using indirect addressing):
assembly
Copy code
MOV Ri, #address
MOV address, #data
ADD A, @Ri
Example Program:
Suppose we want to add the numbers 0x05 and 0x03 and store the result in the accumulator.
assembly
Copy code
MOV A, #0x05 ; Load 0x05 into the accumulator
ADD A, #0x03 ; Add 0x03 to the accumulator
; The result (0x08) is now in the accumulator
This program will load 0x05 into the accumulator and then add 0x03 to it, resulting in 0x08 in the accumulator.
Remember to handle potential overflow if the result exceeds the 8-bit limit (255 or 0xFF). The carry flag (CY) in the Program Status Word (PSW) will be set if there is an overflow.