Table of contents
(1) Data transmission instructions
(2) Arithmetic operation instructions
(3) Logical operation instructions
(4) Control transfer instructions
(5) Bit operation instructions
2. Assembly language programming
1. Command system
- The collection of various instructions that the microcontroller can execute is called the instruction system . The instruction system of the 80C51 has a total of 111 instructions.
- 80C51 assembly language instruction format
Opcode operand 1, operand 2; comments
MOV A, 5BH; (5BH)→A means sending the contents of the internal memory 5BH storage unit to the accumulator A
Operation code: specifies the operation function of the instruction
Operand: the data or the address of the data participating in the operation
Transfer instructions have at most 2 operands
Left operand: destination operand (unit address where the operation result is stored)
Right operand: source operand (the source of the operand)
(〇) Addressing mode (7 types)
- Indicate the number or address of the number involved in the operation
Notation convention | ||
---|---|---|
symbol | meaning | Remark |
Rn | Working register group R0~R7 Determined by RS1 and RS0 in PSW |
There are 4 groups in total from 0 to 3 |
Ri | i = 0, 1; data pointer R0 or R1 Determined by RS1 and RS0 in PSW |
Group 0: 00H, 01H Group 1: 08H, 09H Group 3: 18H, 19H |
#data | 8-bit immediate number, constant | |
#data16 | 16-bit immediate number, constant | |
direct | Direct address unit (including RAM, SFR, I/O) | |
addr11 | 11-digit destination address | PC current address bit base address , Jump to the destination address , is relative to the base address of the PC |
addr16 | 16-bit destination address | |
rel | Relative offset, 8-bit signed number (complement form) | Range +127~-128 |
bit | bit address | |
@ | In indirect addressing mode, the prefix symbol indicating the indirect register | |
X | Direct address (including bit address) or register of on-chip RAM | |
(X) | Represents the content in X | |
((X)) | In the indirect addressing mode, it represents the contents of the address unit pointed by the indirect address register X | |
→ | Data transfer direction |
Addressing mode | |||
---|---|---|---|
Addressing mode | Function Description | Example | Function Description |
1. Register addressing | The operands are stored in the selected register | MOV A,R6 | (R6) → A |
2. Direct addressing | Directly give the address of the operand participating in the operation | MOV A,50H | (50H) → A |
3. Address immediately | Directly give the operands involved in the operation | MOV A,#50H | 50H → A |
4. Register indirect addressing Must be used to access off-chip RAM |
The operand address is stored in the indirect addressing register. R0, R1, SP, and DPTR must be prefixed with @ |
MOV A,@Ri MOVX A,@DPTR |
((Ri)) → A ((DPTR)) → A |
5. Indexed addressing |
Base Address Register: DPTR/PC Index register: Accumulator A "Base register + index register" indirect addressing |
MOVC A,@A+DPTR | ((A+DPTR)) → A |
6. Relative addressing Relative transfer instructions are required |
Transfer to destination address Assembly language can automatically calculate the destination address |
JNZ 30H | 30H is rel (offset) |
7. Bit addressing | Perform bit operations on any binary bit in a bit-addressable SFR | SETB 6AH | Set the 2nd bit in the 2DH unit in the on-chip RAM That is, the position 1 of 6AH |
(1) Data transmission instructions
- 数据传送指令是把源操作数传送到目的操作数,指令执行后,源操作数不改变,目的操作数修改为源操作数。
1. 内部RAM数据传送指令
2. 外部数据传送指令(只能用寄存器间接寻址)
3. 查表指令
4. 堆栈操作指令(PUSH/POP)
5. 交换指令(都需要借助A)
(二)算数运算类指令
1. 加法指令
2. 带进位加法指令
3. 带借位减法指令
4. 乘法指令(低A高B)
5. 除法指令(商A余B)
6. 加1/减1指令
7. 十进制调整指令(对非法BCD码进行修正,不是进制转换指令)
(三)逻辑操作类指令
1. 逻辑与指令
2. 逻辑或指令
3. 逻辑异或指令
4. 循环位移指令(只能对A操作)
5. 取反指令
6. 清零指令(只能对A操作)
(四)控制转移类指令
1. 无条件转移指令
2. 条件转移指令
3. 调用子程序及返回指令
4. 空操作指令
(五)位操作类指令
1. 位数据传送指令
2. 位修正指令
3. 位逻辑运算指令
4. 判位转移指令
二、汇编语言程序设计
(一)汇编语言格式
标号: 操作码 操作数 ;注释
P2: MOV A,#60H ;60H→A
(二)伪指令
- 这些指令不属于指令系统,不产生机器代码,只是告诉汇编程序如何进行汇编
伪指令 | ||
---|---|---|
ORG | 汇编起始指令 | |
END | 汇编结束指令 | |
EQU | 赋值指令(等值伪指令) | |
(三)设计步骤
(四)程序结构
1. 顺序
2. 循环
3. 分支
4. 查表
5. 子程序