Sunday, July 7, 2013

Data Transfer Instruction of 8051
This instructions are used to copy the content of source operand to Destination operand


MOV A,Rn - Moves the Rn register to the accumulator
The instruction moves the Rn register to the accumulator. The Rn register is not affected.

EXAMPLE:
MOV A,Rn 

Before execution: R3=58h
After execution: R3=58h A=58h

MOV A,@Ri - Moves the indirect RAM to the accumulator
Description: Instruction moves the indirectly addressed register of RAM to the accumulator. The register address is stored in the Ri register (R0 or R1). The result is stored in the accumulator. The register is not affected.

EXAMPLE:
MOV A,@Ri

Register Address SUM=F2h R0=F2h
Before execution: SUM=58h
After execution: A=58h SUM=58h

MOV A,direct - Moves the direct byte to the accumulator
Description: Instruction moves the direct byte to the accumulator. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh. (0-127 dec.). After executing the instruction, the register is not affected.

EXAMPLE:
MOV A,Rx

Before execution: Rx=68h
After execution: Rx=68h A=68h

MOV Rn,A - Moves the accumulator to the Rn register
Desription: Instruction moves the accumulator to the Rn register. The accumulator is not affected.

EXAMPLE:
MOV Rn,A

Before execution: A=58h
After execution: R3=58h A=58h

MOV A,#data - Moves the immediate data to the accumulator
Desription: Instruction moves the immediate data to the accumulator.

EXAMPLE:
MOV A,#X

After execution: A=28h

MOV Rn,#data - Moves the immediate data to the Rn register
Description: Instruction moves the immediate data to the Rn register.
MOV Rn,#X

After execution: R5=32h

MOV Rn,direct - Moves the direct byte to the Rn register
Description: Instruction moves the direct byte to the Rn register. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh. (0-127 dec.). After executing the instruction, the register is not affected.

EXAMPLE:
MOV Rn,Rx

Before execution: SUM=58h
After execution: SUM=58h R3=58h

MOV direct,Rn - Moves the Rn register to the direct byte
Description: Instruction moves the Rn register to the direct byte. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh. (0-127 dec.). After executing the instruction, the register is not affected.

EXAMPLE:
MOV Rx,Rn

Before execution: R3=18h
After execution: R3=18h CIF=18h

MOV direct,A - Moves the accumulator to the direct byte
Description: Instruction moves the accumulator to the direct byte. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh. (0-127 dec.). After executing the instruction, the register is not affected.

EXAMPLE:
MOV Rx,A

Before execution: A=98h
After execution: A=98h REG=98h

MOV direct,@Ri - Moves the indirect RAM to the direct byte
Description: Instruction moves the indirectly adressed register of RAM to the direct byte. The register is not affected.

EXAMPLE:
MOV Rx,@Ri

Register Address SUM=F3
Before execution: SUM=58h R1=F3
After execution: SUM=58h TEMP=58h

MOV direct1,direct2 - Moves the direct byte to the direct byte
Description: Instruction moves the direct byte to another direct byte. As it is direct addressing, both registers can be any SFRs or general-purpose registers with address 0-7Fh. (0-127 dec.). The direct1 is not affected.

EXAMPLE:
MOV Rx,Ry

Before execution: TEMP=58h
After execution: TEMP=58h SUM=58h

MOV @Ri,A - Moves the accumulator to the indirect RAM
Description: Instruction moves the accumulator to the indirectly addressed register of RAM. The register address is stored in the Ri register (R0 or R1). After executing the instruction, the accumulator is not affected.

EXAMPLE:
MOV @Ri,A

Register Address SUM=F2h
Before execution: R0=F2h A=58h
After execution: SUM=58h A=58h

MOV direct,#data - Moves the immediate data to the direct byte
Description: Instruction moves the immediate data to the direct byte. As it is direct addressing, the direct byte can be any SFRs or general-purpose register with address 0-7Fh. (0-127 dec.).

EXAMPLE:
MOV Rx,#X

After execution: TEMP=22h

MOV @Ri,#data - Moves the immediate data to the indirect RAM
Description: Instruction moves the immediate data to the idirectly addressed register of RAM. The register address is stored in the Ri register (R0 or R1).


EXAMPLE:
MOV @Ri,#X

Register address TEMP=E2h
Before execution: R1=E2h
After execution: TEMP=44h

MOV @Ri,direct - Moves the direct byte to the indirect RAM
Description: Instruction moves the direct byte to a register the address of which is stored in the Ri register (R0 or R1). After executing the instruction, the direct byte is not affected.

EXAMPLE:
MOV @Ri,Rx

Register address TEMP=E2h
Before execution: SUM=58h R1=E2h
After execution: SUM=58h TEMP=58h

MOVC A,@A+DPTR - Moves the code byte relative to the DPTR to the accumulator
Description: Instruction first adds the 16-bit DPTR register to the accumulator. The result of addition is then used as a memory address from which the 8-bit data is moved to the accumulator.

EXAMPLE:
MOVC A,@A+DPTR

Before execution:
DPTR=1000:
A=0
A=1
A=2
A=3
After execution:
A=66h
A=77h
A=88h
A=99h
Note: DB (Define Byte) is a directive in assembly language used to define constant.

MOV DPTR,#data16 - Loads the data pointer with a 16-bit constant
Description: Instruction stores a 16-bit constant to the DPTR register. The 8 high bits of the constant are stored in the DPH register, while the 8 low bits are stored in the DPL register.

EXAMPLE:
MOV DPTR,#X16

After execution: DPH=12h DPL=34h

MOVX A,@Ri - Moves the external RAM (8-bit address) to the accumulator
Description: Instruction reads the content of a register in external RAM and moves it to the accumulator. The register address is stored in the Ri register (R0 or R1).

EXAMPLE:
MOVX A,@Ri

Register Address: SUM=12h
Before execution: SUM=58h R0=12h
After execution: A=58h
Note:
SUM Register is stored in external RAM which is 256 bytes in size.

MOVC A,@A+PC - Moves the code byte relative to the PC to the accumulator
Description: Instruction first adds the 16-bit PC register to the accumulator (the current program address is stored in the PC register). The result of addition is then used as a memory address from which the 8-bit data is moved to the accumulator.


EXAMPLE:
MOVC A,@A+PC

After the subroutine "Table" has been executed, one of four values is stored in the accumulator:
Before execution:
A=0
A=1
A=2
A=3
After execution:
A=66h
A=77h
A=88h
A=99h
Note: DB (Define Byte) is a directive in assembly language used to define constant.

MOVX @Ri,A - Moves the accumulator to the external RAM (8-bit address)
Description: Instruction moves the accumulator to a register stored in external RAM. Its address is stored in the Ri register.

EXAMPLE:
MOVX @Ri,A 

Register address: SUM=34h
Before execution: A=58 R1=34h
After execution: SUM=58h
NOTE:
Register SUM is located in external RAM which is 256 bytes in size.

MOVX A,@DPTR - Moves the external memory (16-bit address) to the accumulator
Description: Instruction moves the content of a register in external memory to the accumulator. The 16-bit address of the register is stored in the DPTR register (DPH and DPL).

EXAMPLE:
MOVX A,@DPTR

Register address: SUM=1234h
Before execution: DPTR=1234h SUM=58
After execution: A=58h
Note:
Register SUM is located in external RAM which is up to 64K in size.

MOVX @DPTR,A - Moves the accumulator to the external RAM (16-bit address)
Description: Instruction moves the accumulator to a register stored in external RAM. The 16-bit address of the register is stored in the DPTR register (DPH and DPL).

EXAMPLE:
MOVX @DPTR,A

Register address: SUM=1234h
Before execution: A=58 DPTR=1234h
After execution: SUM=58h

Friday, July 5, 2013

Bit-oriented Instructions

Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is that these are performed upon single bits.


ANL C,bit - AND direct bit to the carry flag
C: Carry flag
 Bit: any bit of RAM

Description: Instruction performs logic AND operation between the direct bit and the carry flag.
EXAMPLE:
 ANL C,bit

Before execution: ACC= 43h (01000011 Bin.)
C=1
After execution: ACC= 43h (01000011 Bin.)
C=0

ANL C,/bit - AND complements of direct bit to the carry flag
C: carry flag
 Bit: any bit of RAM

Description: Instruction performs logic AND operation between inverted addressed bit and the carry flag. The result is stored in the carry flag.
EXAMPLE:
ANL C,/bit
Before execution: ACC= 43h (01000011 Bin.)
C=1
After execution: ACC= 43h (01000011 Bin.)
C=1

CLR C - clears the carry flag
C: Carry flag
Description: Instruction clears the carry flag.

EXAMPLE:
CLR C
After execution: C=0

CLR bit - clears the direct bit
Bit: any bit of RAM
Description: Instruction clears the specified bit.

EXAMPLE:
CLR bit
Before execution: P0.3=1 (input pin)
After execution: P0.3=0 (output pin)

CPL bit - Complements the direct bit
Bit: any bit of RAM
Description: Instruction coplements the specified bit of RAM (0==>1, 1==>0).

EXAMPLE:
CPL bit
Before execution: P0.3=1 (input pin)
After execution: P0.3=0 (output pin)

CPL C - Complements the carry flag
C: Carry flag
Description: Instruction complements the carry flag (0==>1, 1==>0).

EXAMPLE:
CPL C
Before execution: C=1
After execution: C=0

MOV bit,C - Moves the carry flag to the direct bit
C: Carry flag
 Bit: any bit of RAM

Description: Instruction moves the carry flag to the direct bit. After executing the instruction, the carry flag is not affected.

EXAMPLE:
MOV bit,C
After execution: If C=0 P1.2=0
If C=1 P1.2=1

MOV C,bit - Moves the direct bit to the carry flag
C: Carry flag
 Bit: any bit of RAM

Description: Instruction moves the direct bit to the carry flag. After executing the instruction, the bit is not affected.

EXAMPLE:
MOV C,bit
After execution: If P1.4=0 C=0
If P1.4=1 C=1

ORL C,bit - OR direct bit to the carry flag
C: Carry flag
 Bit: any bit of RAM

Description: Instruction performs logic OR operation between the direct bit and the carry flag. The result is stored in the carry flag.

EXAMPLE:
ORL C,bit
Before execution: ACC= C6h (11001010 Bin.)
C=0
After execution: C=1

ORL C,/bit - OR complements of direct bit to the carry flag
C: carry flag
 Bit: any bit of RAM

Description: Instruction performs logic OR operation between the addressed inverted bit and the carry flag. The result is stored in the carry flag.

EXAMPLE:
ORL C,/bit

Before execution: ACC= C6h (11001010 Bin.)
C=0
After execution: C=0

SETB C - Sets the carry flag
C: Carry flag
Description: Instruction sets the carry flag.

EXAMPLE:
SETB C After execution: C=1

SETB bit - Sets the direct bit
Bit: any bit of RAM
Description: Instruction sets the specified bit. The register containing that bit must belong to the group of the so called bit addressable registers.

EXAMPLE:
SETB bit
Before execution: P0.1 = 34h (00110100)
pin 1 is configured as an output
After execution: P0.1 = 35h (00110101)
pin 1 is configured as an input

Next Post:Logical Instruction
Previous Post:Arithmetic Instruction
 

Related Topics:

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









Logical Instruction Of 8051 Micro-Controller

Logic instructions perform logic operations upon corresponding bits of two registers. After execution, the result is stored in the first operand.


ANL A,Rn - AND register to the accumulator
A: accumulator
 Rn: any R register (R0-R7)

Description: Instruction performs logic AND operation between the accumulator and Rn register. The result is stored in the accumulator.

EXAMPLE:
ANL A,Rn
Before execution: A= C3h (11000011 Bin.)
R5= 55h (01010101 Bin.)
After execution: A= 41h (01000001 Bin.)

ANL A,direct - AND direct byte to the accumulator
A: accumulator
 Direct: arbitrary register with address 0 - 255 (0 - FFh)

Description: Instruction performs logic AND operation between the accumulator and drect register. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh (o-127 dec.). The result is stored in the accumulator.

EXAMPLE:
ANL A,Rx
Before execution: A= C3h (11000011 Bin.)
MASK= 55h (01010101 Bin.)
After execution: A= 41h (01000001 Bin.)

ANL A,@Ri - AND indirect RAM to the accumulator
A: accumulator
 Ri: Register R0 or R1

Description: Instruction performs logic AND operation between the accumulator and register. 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:
ANL A,@Ri
Register address SUM = 4Fh R0=4Fh
Before execution: A= C3h (11000011 Bin.)
R0= 55h (01010101 Bin.)
After execution: A= 41h (01000001 Bin.)

ANL A,#data - AND immediate data to the accumulator
A: accumulator
 Data: constant in the range of 0-255 (0-FFh)

Description: Instruction performs logic AND operation between the accumulator and data. The result is stored in the accumulator.

EXAMPLE:
ANL A,#X
Before execution: A= C3h (11000011 Bin.)
After execution: A= 41h (01000001 Bin.)

ANL direct,A - AND accumulator to direct byte
Direct: arbitrary register with address 0-255 (0-FFh)
 A: accumulator

Description: Instruction performs logic AND operation between direct byte and accumulator. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh (0-127 dec.). The result is stored in the direct byte.

EXAMPLE:
ANL Rx,A
Before execution: A= C3h (11000011 Bin.)
MASK= 55h (01010101 Bin.)
After execution: MASK= 41h (01000001 Bin.)

ANL direct,#data - AND immediate data to direct byte
Direct: Arbitrary register with address 0 - 255 (0 - FFh)
 Data: constant in the range between 0-255 (0-FFh)

Description: Instruction performs logic AND operation between direct byte and data. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh (0-127 dec.). The result is stored in the direct byte.

EXAMPLE:
ANL Rx,#X
Before execution: X= C3h (11000011 Bin.) MASK= 55h (01010101 Bin.) After execution: MASK= 41h (01000001 Bin.)

ANL C,bit - AND direct bit to the carry flag
C: Carry flag
EXAMPLE:
ANL C,bit

Before execution: ACC= 43h (01000011 Bin.)
C=1
After execution: ACC= 43h (01000011 Bin.)
C=0


ANL C,/bit - AND complements of direct bit to the carry flag
C: carry flag
 Bit: any bit of RAM

Description: Instruction performs logic AND operation between inverted addressed bit and the carry flag. The result is stored in the carry flag.

EXAMPLE:
ANL C,/bit
Before execution: ACC= 43h (01000011 Bin.)
C=1
After execution: ACC= 43h (01000011 Bin.)
C=1

ORL A,Rn - OR register to the accumulator
Rn: any R register (R0-R7)
 A: accumulator

Description: Instruction performs logic OR operation between the accumulator and Rn register. The result is stored in the accumulator.

EXAMPLE:
ORL A,Rn
Before execution: A= C3h (11000011 Bin.)
R5= 55h (01010101 Bin.)
After execution: A= D7h (11010111 Bin.)

ORL A,@Ri - OR indirect RAM to the accumulator
Ri: register R0 or R1
 A: accumulator

Description: Instruction performs logic OR operation between the accumulator and a register. As it is indirect addressing, the register address is stored in the Ri register (R0 or R1). The result is stored in the accumulator.
d;
EXAMPLE:
ANL A,@Ri
Register address: TEMP=FAh
Before execution: R1=FAh
TEMP= C2h (11000010 Bin.)
A= 54h (01010100 Bin.)
After execution: A= D6h (11010110 Bin.)

ORL A,direct - OR direct byte to the accumulator
Direct: arbitrary register with address 0-255 (0-FFh)
 A: accumulator

Description: Instruction performs logic OR operation between the accumulator and a register. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh (0-127 dec.). The result is stored in the accumulator.

EXAMPLE:
ORL A,Rx
Before execution: A= C2h (11000010 Bin.)
LOG= 54h (01010100 Bin.)
After execution: A= D6h (11010110 Bin.)

ORL direct,A - OR accumulator to the direct byte
Direct: arbitrary register with address 0-255 (0-FFh)
 A: accumulator

Description: Instruction performs logic OR operation between a register and accumulator. As it is direct addressing, the register can be any SFRs or general- purpose register with address 0-7Fh (0-127 dec.). The result is stored in the register.

EXAMPLE:
ORL Rx,A
Before execution: TEMP= C2h (11000010 Bin.)
A= 54h (01010100 Bin.)
After execution: A= D6h (11010110 Bin.)

ORL A,#data - OR immediate data to the accumulator
Data: constant in the range of 0-255 (0-FFh)
 A: accumulator

Description: Instruction performs logic OR operation between the accumulator and the immediate data. The result is stored in the accumulator.

EXAMPLE:
ORL A, #X
Before execution: A= C2h (11000010 Bin.)
After execution: A= C3h (11000011 Bin.)

ORL C,bit - OR direct bit to the carry flag
C: Carry flag
 Bit: any bit of RAM

Description: Instruction performs logic OR operation between the direct bit and the carry flag. The result is stored in the carry flag.

EXAMPLE:
ORL C,bit
Before execution: ACC= C6h (11001010 Bin.)
C=0
After execution: C=1

ORL direct,#data - OR immediate data to direct byte
Direct: arbitrary register with address 0-255 (0-FFh)
 Data: constant in the range of 0-255 (0-FFh)

Description: Instruction performs logic OR operation between the immediate data and the direct byte. 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 direct byte.

EXAMPLE:
ORL Rx,#X
Before execution: TEMP= C2h (11000010 Bin.)
After execution: A= D2h (11010010 Bin.)


XRL A,Rn - Exclusive OR register to accumulator
Rn: any R register (R0-R7)
 A: accumulator

Description: Instruction performs exclusive OR operation between the accumulator and the Rn register. The result is stored in the accumulator.

EXAMPLE:
XRL A,Rn
Before execution: A= C3h (11000011 Bin.)
R3= 55h (01010101 Bin.)
After execution: A= 96h (10010110 Bin.)

Register address: SUM=E3
Before execution: R0=E3 SUM=29h A=A8h,
After execution: A=A9h, SUM=28h

XRL A,@Ri - Exclusive OR indirect RAM to the accumulator
Ri: Register R0 or R1
 A: accumulator

Description: Instruction performs exclusive OR operation between the accumulator and the indirectly addressed register. 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:
XRL A,@Ri
Register address: TEMP=FAh, R1=FAh
Before execution: TEMP= C2h (11000010 Bin.)
A= 54h (01010100 Bin.)
After execution: A= 96h (10010110 Bin.)

XRL A,direct - Exclusive OR direct byte to the accumulator
Direct: Arbitrary register with address 0-255 (0-FFh)
 A: accumulator

Description: Instruction performs exclusive OR operation between the accumulator and the direct byte. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh (0-127 dec.). The result is stored in the accumulator.

EXAMPLE:
XRL A,Rx
Before execution: A= C2h (11000010 Bin.)
LOG= 54h (01010100 Bin.)
After execution: A= 96h (10010110 Bin.)

XRL direct,A - Exclusive OR accumulator to the direct byte
Direct: arbitrary register with address 0-255 (0-FFh)
 A: accumulator

Description: Instruction performs exclusive OR operation between the direct byte and the accumulator. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh (0-127 dec.). The result is stored in the register.

EXAMPLE:
XRL Rx,A
Before execution: TEMP= C2h (11000010 Bin.)
A= 54h (01010100 Bin.)
After execution: A= 96h (10010110 Bin.)

XRL A,#data - Exclusive OR immediate data to the accumulator
Data: constant in the range of 0-255 (0-FFh)
 A: accumulator

Description: Instruction performs exclusive OR operation between the accumulator and the immediate data. The result is stored in the accumulator.

EXAMPLE:
XRL A,#X
Before execution: A= C2h (11000010 Bin.)
X= 11h (00010001 Bin.)
After execution: A= D3h (11010011 Bin.)

XRL direct,#data - Exclusive OR immediate data to direct byte
Direct: arbitrary register with address 0-255 (0-FFh)
 Data: constant in the range of 0-255 (0-FFh)

Description: Instruction performs exclusive OR operation between the immediate data and the direct byte. As it is direct addressing, the register can be any SFRs or general-purpose register with address 0-7Fh (0-127 dec.). The result is stored in the register.

EXAMPLE:
XRL Rx,#X
Before execution: TEMP= C2h (11000010 Bin.)
X=12h (00010010 Bin.)
After execution: A= D0h (11010000 Bin.)

CLR A - Clears the accumulator
A: accumulator
Description: Instruction clears the accumulator.

EXAMPLE:
CLR A
After execution: A=0

CPL A - Complements the accumulator
A: accumulator
Description: Instruction complements all the bits in the accumulator (1==>0, 0==>1).

EXAMPLE:
CPL A
Before execution: A= (00110110)
After execution: A= (11001001)

RL A - Rotates the accumulator one bit left
A: accumulator
Description: Eight bits in the accumulator are rotated one bit left, so that the bit 7 is rotated into the bit 0 position.

EXAMPLE:
RL A
Before execution: A= C2h (11000010 Bin.)
After execution: A=85h (10000101 Bin.)
RL A

RR A - Rotates the accumulator one bit right
A: accumulator
Description: All eight bits in the accumulator are rotated one bit right so that the bit 0 is rotated into the bit 7 position.

EXAMPLE:
RR A
Before execution: A= C2h (11000010 Bin.)
After execution: A= 61h (01100001 Bin.)
Rotate Right
RLC A - Rotates the accumulator one bit left through the carry flag
A: accumulator
Description: All eight bits in the accumulator and carry flag are rotated one bit left. After this operation, the bit 7 is rotated into the carry flag position and the carry flag is rotated into the bit 0 position.

EXAMPLE:
RLC A
Before execution: A= C2h (11000010 Bin.)
C=0
After execution: A= 85h (10000100 Bin.)
C=1
Rotate Left Through Carry Bit

RRC A - Rotates the accumulator one bit right through the carry flag
A: accumulator
Description: All eight bits in the accumulator and carry flag are rotated one bit right. After this operation, the carry flag is rotated into the bit 7 position and the bit 0 is rotated into the carry flag position.

EXAMPLE:
RRC A
Before execution: A= C2h (11000010 Bin.)
C=0
After execution: A= 61h (01100001 Bin.)
C=0
Rotate Right Through Carry Bit
 SWAP A - Swaps nibbles within the accumulator
A: accumulator
Description: A nibble refers to a group of 4 bits within one register (bit0-bit3 and bit4-bit7). This instruction interchanges high and low nibbles of the accumulator.

EXAMPLE:
SWAP A

Before execution: A=E1h (11100001)bin.
After execution: A=1Eh (00011110)bin.
Swap nibbles within accumulator
Next Post: Arithmetic 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






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