The ADD instruction has the following format:
ADD A, source ; ADD the source operand to the accumulator
The ADD instruction tells the CPU to add the source byte to register A and put the result in register A. To add two numbers such as 25H and 34H, each can be moved to a register and then added together:
MOV A, #25H; load 25H into A
MOV R2, #34H; load 34H into R2
ADD A, R2; add R2 to accumulator (A = A + R2)
Add – ADD A, src-byte
ADD adds the byte variable indicated to the Accumulator, leaving the result in the Accumulator. The carry and auxiliary-carry flags are set, respectively, if there is a carry-out from bit 7 or bit 3, and cleared otherwise. When adding unsigned integers, the carry flag indicates an overflow occurred. OV is set if there is a carry-out of bit 6 but not out of bit 7, or a carry-out of bit 7 but not bit 6; otherwise, OV is cleared. When adding signed integers, OV indicates a negative number produced as the sum of two positive operands, or a positive sum from two negative operands. Four source operand addressing modes are allowed: register, direct, register-indirect, or immediate.
ADD A,Rn
Encoding:00101nnn
ADD A,direct address
Encoding:00100101 direct address
ADD A,@Ri
Encoding:0010011i
ADD A, #immediate data
Encoding:00100100 immediate data
Example:
ADD A, source ; ADD the source operand to the accumulator
The ADD instruction tells the CPU to add the source byte to register A and put the result in register A. To add two numbers such as 25H and 34H, each can be moved to a register and then added together:
MOV A, #25H; load 25H into A
MOV R2, #34H; load 34H into R2
ADD A, R2; add R2 to accumulator (A = A + R2)
Add – ADD A, src-byte
ADD adds the byte variable indicated to the Accumulator, leaving the result in the Accumulator. The carry and auxiliary-carry flags are set, respectively, if there is a carry-out from bit 7 or bit 3, and cleared otherwise. When adding unsigned integers, the carry flag indicates an overflow occurred. OV is set if there is a carry-out of bit 6 but not out of bit 7, or a carry-out of bit 7 but not bit 6; otherwise, OV is cleared. When adding signed integers, OV indicates a negative number produced as the sum of two positive operands, or a positive sum from two negative operands. Four source operand addressing modes are allowed: register, direct, register-indirect, or immediate.
ADD A,Rn
Encoding:00101nnn
ADD A,direct address
Encoding:00100101 direct address
ADD A,@Ri
Encoding:0010011i
ADD A, #immediate data
Encoding:00100100 immediate data
Example:
ORG 0H
MAIN :
MOV A, #0H
MOV R0, #55H ; load 55H in to R0
MOV R1, #90H ; load 90H in to R1
MOV 20H, #33H ; load 33H in to memory location 20h
ADD A, R0
ADD A, 20h
ADD A, @R1
ADD A, #03h
END ; end of asm source file
Related topics:
8051 Addition with Carry | 8051 Addition of Unsigned Numbers | 8051 Addition of 16-bit Numbers | 8051 Binary Coded Decimal | 8051 ADDC Instruction | 8051 ADD Instruction | 8051 Signed Numbers
List of topics: 8051
No comments:
Post a Comment