📜  嵌入式系统8051指令集

📅  最后修改于: 2021-01-01 02:50:25             🧑  作者: Mango

8051指令集

指令是给微控制器的命令,用于对显示的数据执行指定的操作。微控制器的指令集是微控制器旨在执行的指令的集合。

数据移动或处理说明:

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

循环和跳转说明:

8051中的循环操作:

在重复执行一系列指令时,将导致循环的形成。根据需要,循环操作用于在程序内运行同一组子例程的次数。

考虑指令DJNZ寄存器;标签用于执行循环操作。在该指令中,寄存器减1;否则,寄存器减1。如果不为零,则8051跳转到标签所引用的目标地址。

示例:使用重复加法的技术将15乘以10

解决方案:可以通过重复乘数与乘数相同的次数来执行乘法。

例如:


MOV A,#0             ;A = 0,clean ACC 
MOV R1,#10          ; the multiplier is replaced in R1 
Add A,#15              ;add the multiplicand to the ACC 
    
AGAIN: DJNZ R1, 
AGAIN: repeat  until R1 = 0 (10 times) 

   MOV R5 , A           ;save A in R5 ;R5 (96H)

条件跳转指令:

考虑下表列出了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