Thursday, July 4, 2013

8051 Instruction Set
8051 micro controller have reach set of instruction to perform different operation in 8051 micro-controller.
There are  five group of instruction which are listed below.
  • Arithmetic Instructions
  • Branch Instructions
  • Data Transfer Instructions
  • Logic Instructions
  • Bit-oriented Instructions
Arithmetic instruction:
Arithmetic instructions perform several basic operations such as addition, subtraction, division, multiplication etc. After execution, the result is stored in the first operand.
1.ADD A,Rn;Adds the register Rn to the accumulator
Description: Instruction adds the register Rn (R0-R7) to the accumulator. After addition, the result is stored in the accumulator
ADD A,Rn
Before execution: A=2Eh  R4=12h
After execution:    A=40h  R4=12h

2.ADD A,@Ri - Adds the indirect RAM to the accumulator.
 Ri: Register R0 or R1 
Description: Instruction adds the indirect RAM to the accumulator. Address of indirect RAM is stored in the Ri register (R0 or R1). After addition, the result is stored in the accumulator.
ADD A,@Ri
Register address:R0=4Fh
Before execution: A= 16h SUM= 33h
After execution : A= 49h 

3.ADD A,direct - Adds the direct byte to the accumulator
 Direct: Arbitrary register with address 0 - 255 (0 - FFh)
Description: Instruction adds the direct byte to the accumulator. As it is direct addressing, the direct can be any SFR or general-purpose register with address 0-7 Fh. The result is stored in the accumulator.
ADD A,Rx

4.ADDC A,Rn - Adds the register to the accumulator with a carry flag
 Rn: any R register (R0-R7)
Description: Instruction adds the accumulator with a carry flag and Rn register (R0-R7). After addition, the result is stored in the accumulator.
ADD A,direct

5.ADD A,#DATA
Data: constant within 0-255 (0-FFh)
Description: Instruction adds data (0-255) to the accumulator. After addition, the result is stored in the accumulator.
ADD A,#XBefore execution: A= 16h (22 dec.)
After execution: A= 49h (73 dec.)

6.ADDC A,direct - Adds the direct byte to the acumulator with a carry flag
 Direct: arbitrary register with address 0-255 (0-FFh)
Description: Instruction adds the direct byte to the accumulator with a carry flag. As it is direct addressing, the register can be any SFRs or general purpose register with address 0-7Fh (0-127dec.). The result is stored in the accumulator.
ADDC A,Rx
Before execution: A= C3h (195 dec.) TEMP = AAh (170 dec.) C=1
After execution: A= 6Eh (110 dec.) AC=0, C=1, OV=1

7.ADDC A,@Ri - Adds the indirect RAM to the accumulator with a carry flag
 Ri: Register R0 or R1
Description: Instruction adds the indirect RAM to the accumulator with a carry flag. RAM address is stored in the Ri register (R0 or R1). After addition, the result is stored in the accumulator.

EXAMPLE:
ADDC A,@Ri
Register address: SUM = 4Fh R0=4Fh
Before execution: A= C3h (195 dec.) SUM = AAh (170 dec.) C=1
After execution: A= 6Eh (110 dec.) AC=0, C=1, OV=1

8.ADDC A,#data - Adds the immediate data to the accumulator with a carry flag
 Data: constant with address 0-255 (0-FFh)
Description: Instruction adds data (0-255) to the accumulator with a carry flag. After addition, the result is stored in the accumulator.

EXAMPLE:
ADDC A,#X
Before execution: A= C3h (195 dec.) C=1
After execution: A= 6Dh (109 dec.) AC=0, C=1, OV=1

9.SUBB A,direct - Subtracts the direct byte from the accumulator with a borrow
Direct: arbitrary register with address 0-255 (0-FFh)

Description: Instruction subtracts the direct byte from the accumulator with a borrow. If the higher bit is subtracted from the lower bit then the carry flag is set. As it is direct addressing, the direct byte can be any SFRs or general-purpose register with address 0-7Fh. (0-127 dec.). The result is stored in the accumulator.

EXAMPLE:
SUBB A,Rx
Before execution: A=C9h, DIF=53h, C=0
After execution: A=76h, C=0

10.SUBB A,Rn - Subtracts the Rn register from the accumulator with a borrow
Rn: any R register (R0-R7)

Description: Instruction subtracts the Rn register from the accumulator with a borrow. If the higher bit is subtracted from the lower bit then the carry flag is set. The result is stored in the accumulator.

EXAMPLE:
SUBB A,Rn
Before execution: A=C9h, R4=54h, C=1
After execution: A=74h, C=0
Note:
The result is different (C9 - 54=75) because the carry flag is set (C=1) before the instruction starts execution.

11.SUBB A,#data - Subtracts the immediate data from the accumulator with a borrow
 Data: constant in the range of 0-255 (0-FFh)
Description: Instruction subtracts the immediate data from the accumulator with a borrow. If the higher bit is subtracted from the lower bit then the carry flag is set. The result is stored in the accumulator.

EXAMPLE:
SUBB A,#X
Before execution: A=C9h, C=0
After execution: A=A7h, C=0

12.SUBB A,@Ri - Subtracts the indirect RAM from the accumulator with a borrow
Ri: register R0 or R1

Description: Instruction subtracts the indirectly addressed register of RAM from the accumulator with a borrow. If the higher bit is subtracted from the lower bit then the carry flag is set. As it is indirect addressing, the register address is stored in the Ri register (R0 or R1). The result is stored in the accumulator.

EXAMPLE:
SUBB A,@Ri
Register address: MIN=F4
Before execution: A=C9h, R1=F4h, MIN=04, C=0
After execution: A=C5h, C=0

13.INC Rn - Increments the Rn register by 1
Rn: any R register (R0-R7)
Description: Instruction increments the value in the Rn register by 1. If the register includes the number 255, the result of the operation will be 0.

EXAMPLE:
INC Rn
Before execution: R4=18h
After execution: R4=19h

14.INC A - Increments the accumulator by 1
A: accumulator
Description: This instruction increments the value in the accumulator by 1. If the accumulator includes the number 255, the result of the operation will be 0.

EXAMPLE:
INC A
Before execution: A=E4h
After execution: A=E5h

15.INC @Ri - Increments the value of indirectly addressed register of RAM by 1
Ri: Register R0 or R1
Description: This instruction increments the value in the directly addressed register of RAM by 1. The register address is stored in the Ri Register (R0 or R1). If the register includes the number 255, the result of the operation will be 0.

EXAMPLE:
INC @Ri
Register Address CNT = 4Fh
Before execution: CNT=35h R1=4Fh
After execution: CNT=36h

16.INC direct - Increments the direct byte by 1
Direct: arbitrary register with address 0-255 (0-FFh)
Description: Instruction increments the direct byte by 1. If the register includes the number 255, the result of the operation will be 0. As it is direct addressing, the register must be within the first 255 RAM locations.

EXAMPLE:
INC Rx
Before execution: CNT=33h
After execution: CNT=34h

17.DEC A - Decrements the accumulator by 1
A: accumulator
Description: Instruction decrements the value in the accumulator by 1. If there is a 0 in the accumulator, the result of the operation is FFh. (255 dec.)
Syntax: DEC A;
Byte: 1 (instruction code);
STATUS register flags: No flags are affected;
EXAMPLE:
DEC A
Before execution: A=E4h
After execution: A=E3h

18.DEC Rn - Decrements the register Rn by 1
Rn: any R register (R0-R7)
Description: Instruction decrements the value in the Rn register by 1. If there is a 0 in the register, the result of the operation will be FFh. (255 dec.)
Syntax: DEC Rn;
Byte: 1 (instruction code);
STATUS register flags: No flags are affected;
EXAMPLE:
DEC Rn
Before execution: R3=B0h
After execution: R3=AFh

19.DEC direct - Decrements the direct byte by 1
Direct: arbitrary register with address 0-255 (0-FFh)
Description: Instruction decrements the value of directly addressed register by 1. As it is direct addressing, the register must be within the first 255 locations of RAM. If there is a 0 in the register, the result will be FFh.

EXAMPLE:
DEC Rx
Before execution: CNT=0
After execution: CNT=FFh

20.DIV AB - Divides the accumulator by the register B
Description: Instruction divides the value in the accumulator by the value in the B register. After division the integer part of result is stored in the accumulator while the register contains the remainder. In case of dividing by 1, the flag OV is set and the result of division is unpredictable. The 8-bit quotient is stored in the accumulator and the 8-bit remainder is stored in the B register.

EXAMPLE:
DIV AB
Before execution: A=FBh (251dec.) B=12h (18 dec.)
After execution: A=0Dh (13dec.) B=11h (17dec.)
13·18 + 17 =251

21.DA A - Decimal adjust accumulator
Description: Instruction adjusts the contents of the accumulator to correspond to a BCD number after two BCD numbers have been added by the ADD and ADDC instructions. The result in form of two 4-digit BCD numbers is stored in the accumulator.

EXAMPLE:
DA A
Before execution: A=56h (01010110) 56 BCD
B=67h (01100111) 67BCD
After execution: A=BDh (10111101)
After BCD conversion: A=23h (00100011), C=1 (Overflow)
(C+23=123) = 56+67

22.MUL AB - Multiplies A and B
Description: Instruction multiplies the value in the accumulator with the value in the B register. The low-order byte of the 16-bit result is stored in the accumulator, while the high byte remains in the B register. If the result is larger than 255, the overflow flag is set. The carry flag is not affected.

EXAMPLE:
MUL AB
 Before execution: A=80 (50h) B=160 (A0h)
After execution: A=0 B=32h
A·B=80·160=12800 (3200h)

Next Post:Logical Instruction
Related Topics:

-> Instruction set of 8051 microcontroller
-> I/O PROGRAMMING OF 8051
-> Reset & Oscillator Circuit of 8051 Micro-Controller
-> Program Status Word-(PSW) of 8051
-> Internal RAM structure of 8051 comtroller
 



0 comments:

Related Posts Plugin for WordPress, Blogger...
Subscribe to RSS Feed Follow me on Twitter!