8051 Instruction Set
An instruction is a command given to the microcontroller for performing a specified operation on presented data. The instruction set of microcontroller is a collection of instructions that the microcontroller is designed to execute.
Data moving or handling Instructions:
Mnemonics | Operational descriptions | Addressing modes | No. of cycles used | No. of bytes occupied |
---|---|---|---|---|
Mov a,#num | This instruction Copy the immediate data number in to acc | immediate | 1 | 2 |
Mov Rx,a | This instruction Copy the data from acc to Rx | register | 1 | 1 |
Mov a,Rx | This instruction Copy the data from Rx to acc | register | 1 | 1 |
Mov Rx,#num | This instruction Copy the immediate data num in to Rx | immediate | 1 | 2 |
Mov a,add | This instruction Copy the data from direct address location add to acc | direct | 1 | 2 |
Mov add,a | This instruction Copy the data from acc to direct address add | direct | 1 | 2 |
Mov add,#num | This instruction Copy the immediate data num in to direct address | direct | 2 | 3 |
Mov add1,add2 | This instruction Copy the data from add2 to add1 | direct | 2 | 3 |
Mov Rx,add | This instruction Copy the data from direct | direct | 2 | 2 |
Mov add,Rx | This instruction Copy the data from Rx to direct address add | direct | 2 | 2 |
Mov @Rp,a | This instruction Copy the data in acc to address in Rp | Indirect | 1 | 2 |
Mov a,@Rp | This instruction Copy the data that is at address in Rp to acc | Indirect | 1 | 1 |
Mov add,@Rp | This instruction Copy the data that is at address in Rp to add | Indirect | 2 | 2 |
Mov @Rp,add | This instruction Copy the data in add to address in Rp | Indirect | 2 | 2 |
Mov @Rp,#num | This instruction Copy the immediate byte num to the address in Rp | Indirect | 1 | 2 |
Movx a,@Rp | This instruction Copy the content of external add in Rp to acc | Indirect | 2 | 1 |
Movx a,@DPTR | This instruction Copy the content of external add in DPTR to acc | Indirect | 2 | 1 |
Movx @Rp,a | This instruction Copy the content of acc to the external add in Rp | Indirect | 2 | 1 |
Movx @DPTR,a | This instruction Copy the content of acc to the external add in DPTR | Indirect | 2 | 1 |
Movc a,@a+DPTR | In this the address of instruction is formed by adding acc and DPTR and their content is copied to acc | indirect | 2 | 1 |
Movc a, @a+PC | In this the address of instruction is formed by adding acc and PC and its content is copied to acc | indirect | 2 | 1 |
Push add | In this instruction Increment Stack Pointer (SP) and copy the data from source add to internal RAM address contained in SP | Direct | 2 | 2 |
Pop add | This instruction copy the data from an internal RAM address contained in SP to destination add and decrement SP | direct | 2 | 2 |
Xch a, Rx | This instruction Exchange the data between acc and Rx | Register | 1 | 1 |
Xch a, add | This instruction Exchange the data between acc and given add | Direct | 1 | 2 |
Xch a,@Rp | This instruction Exchange the data between acc and address in Rp | Indirect | 1 | 1 |
Xchd a, @Rp | This instruction Exchange only lower nibble of acc and address in Rp | indirect | 1 | 1 |
Loop and Jump Instructions:
Looping operation in the 8051:
On repeating a sequence of instructions a certain number of times will result in the formation of loop. The looping operation is used for running the same set of subroutine inside a program number of times as per the requirement.
Consider the instruction DJNZ register; label is used for performing a loop operation. In this instruction, the register is decremented by 1; if this is not zero, then 8051 jumps to the target address referred by the label.
Example: Multiply 15 by 10 using the technique of a repeated addition
Solution: Multiplication can be performed by adding the multiplicand repeatedly, as many times as that of multiplier.
For example:
Conditional Jump Instruction:
Consider the below table lists the conditional jumps instruction used in 8051
Instructions | Action |
---|---|
JC | Jump if CY = 1 |
JNC | Jump if CY ≠1 |
JNB | Jump if bit = 0 |
JB | Jump if bit = 1 |
JZ | Jump if A = 0 |
DJNZ | Decrement and Jump if register ≠0 |
JNZ | Jump if A ≠0 |
CJNE A, data | Jump if A ≠data |
CJNE reg, #data | Jump if byte ≠data |
JBC | Jump if bit = 1 and clear bit |