Sunday, February 28, 2016

8051 Arithmetic Operation Instructions

Arithmetic Operations

  • A, Acc: Accumulator
  • B: B special function register
  • C: Carry flag in PSW
  • Rn: Register R7-R0 of the currently selected Register Bank.
  • dir: 8-bit internal data location’s address. This could be an Internal Data RAM location (0-127) or a SFR [i.e., I/O port, control register, status register, etc. (128-255)]. Direct Addressing Mode.
  • @Ri : 8-bit internal data RAM location (0-255) addressed indirectly through register R1or R0. Indirect Addressing Mode.
  • #data: 8-bit constant included in instruction. Immediate Addressing Mode.
  • #data 16: 16-bit constant included in instruction. Immediate Addressing Mode.
  • addr 16: 16-bit destination address. Used by LCALL and LJMP. A branch can be anywhere within the 64K byte Program Memory address space. Long Addressing Mode.
  • addr 11: 11-bit destination address. Used by ACALL and AJMP. The branch will be within the same 2K byte page of program memory as the first byte of the following instruction. Absolute Addressing Mode.
  • rel: Signed (two’s complement) 8-bit offset byte. Used by SJMP and all conditional jumps. Range is -128 to +127 bytes relative to first byte of the following instruction. Relative Addressing Mode.
  • bit: Direct Addressed bit in Internal Data RAM or Special Function Register
  • 1B: 1 byte
    2B: 2 byte
    3B: 3 byte
    1C: 1 cycle
    2C: 2 cycles
    4C: 4 cycles
    P: oscillator period
MnemonicDescription
ADD A,RnAdd register to Accumulator
[1B,1C,12P]
ADDA,directAdd direct byte to Accumulator
[2B,1C,12P]
ADDA,@RiAdd indirect RAM to Accumulator
[1B,1C,12P]
ADDA,#dataAdd immediate data to Accumulator
[2B,1C,12P]
ADDCA,RnAdd register to Accumulator with Carry
[1B,1C,12P]
ADDCA,directAdd direct byte to Accumulator with Carry
[2B,1C,12P]
ADDCA,@RiAdd indirect RAM to Accumulator with Carry
[1B,1C,12P]
ADDCA,#dataAdd immediate data to Acc with Carry
[2B,1C,12P]
SUBBA,RnSubtract Register from Acc with borrow
[1B,1C,12P]
SUBBA,directSubtract direct byte from Acc with borrow
[2B,1C,12P]
SUBBA,@RiSubtract indirect RAM from ACC with borrow
[1B,1C,12P]
SUBBA,#dataSubtract immediate data from Acc with borrow
[2B,1C,12P]
INCAIncrement Accumulator
[1B,1C,12P]
INCRnIncrement register
[1B,1C,12P]
INCdirectIncrement direct byte
[2B,1C,12P]
INC@RiIncrement indirect RAM
[1B,1C,12P]
DECADecrement Accumulator
[1B,1C,12P]
DECRnDecrement register
[1B,1C,12P]
DECdirectDecrement direct byte
[2B,1C,12P]
DEC@RiDecrement indirect RAM
[1B,1C,12P]
INC DPTRIncrement Data Pointer
[1B,2C,24P]
MUL ABMultiply A & B
[1B,4C,48P]
DIV ABDivide A by B
[1B,4C,48P]
DAADecimal Adjust Accumulator
[1B,1C,12P]

Addition
Register A (the accumulator) is used to hold the result of any addition operation. Carry, Auxiliary Carry and Overflow flags in the PSW register are affected by the various addition operations.
ADD A, #25h ; Adds the number 25h to A, putting sum in A
ADD A, R3 ; Adds the register R3 value to A, putting sum in A
ADDC A, #55h ; Add contents of A, the number 55h, the carry bit and put the sum in A
ADDC A, R4 ; Add the contents of A, the register R4, the carry bit and put the sum in A.

Subtraction
Subtraction can be achieved using 2’s complement arithmetic. The accumulator, register A, will contain the result (difference) of the subtraction operation. The C (carry) flag is treated as a borrow flag.
SUBB A, #55d ; Subtract the number 55 (decimal) and the C flag from A and put the result in A.
SUBB A, R6 ; Subtract R6 the C flag from A and put the result in A.
SUBB A, 58h ; Subtract the number in RAM location 58h and the C flag From A and put the result in A.

Increment/Decrement
The increment (INC) instruction has the effect of simply adding a binary 1 to a number while a decrement (DEC) instruction has the effect of subtracting a binary 1 from a number. The DPTR register cannot be decremented using a DEC instruction.
INC R7 ; Increment register R7
INC A ; Increment A
INC @R1 ; Increment the number which is the content of the address in R1
DEC A ; Decrement register A
DEC 43h ; Decrement the number in RAM address 43h
INC DPTR ; Increment the DPTR register

Multiply / Divide
The 8051 supports 8-bit multiplication and division. For the MUL or DIV instructions the A
and B registers must be used and only unsigned numbers are supported.
MUL AB ; Multiply A by B. The resulting product resides in registers A and B, the low-order byte is in A and the high order byte is in B.
DIV AB ; A is divided by B. The remainder is put in register B and the integer part of the quotient is put in register A.

Decimal Adjust
The 8051 performs all arithmetic in binary numbers (i.e. it does not support BCD arithmetic). If two BCD numbers are added then the result can be adjusted by using the DA, decimal adjust, instruction:
DA A ; Decimal adjust A following the addition of two BCD numbers.



Related topics:
8051 Instruction Set Overview   |   8051 Instruction Cycle   |   8051 Machine Cycle   |   8051 Instruction Set Summary   |   8051 Logical Operation Instructions   |   8051 Data Transfer Instructions   |   8051 Boolean Variable Manipulation Instructions   |   8051 Program Branching Instructions   |   8051 Instruction Opcode   |   8051 Instructions that Affect Flag Settings   |   8051 Instructions and Examples

List of topics: 8051

No comments:

Post a Comment