设计与开发

8051单片机汇编 8051指令集和汇编语言程序设计

小编 2024-11-25 设计与开发 23 0

8051指令集和汇编语言程序设计

8051单片机有255条指令。基本上可以分为下面几大类。下面给出各个类别的速记。

1.数据转移类

MOV(Move):对内部数据寄存器RAM和特殊功能寄存器SFR的数据进行传送;(没有MOV Rn,Rn这样的寻址方式)

MOVC(Move Code)读取程序存储器数据表格的数据传送;(只有两条:MOVC A,@A+DPTR和MOVC A,@A+PC)

MOVX (Move External RAM)对外部RAM的数据传送;

XCH (Exchange) 字节交换;

XCHD (Exchange low-order Digit) 低半字节交换;

PUSH (Push onto Stack) 入栈;

POP (Pop from Stack) 出栈;

2.算数运算类

ADD(Addition) 加法;

ADDC(Add with Carry) 带进位加法;

SUBB(Subtract with Borrow) 带借位减法;

DA(Decimal Adjust) 进行BCD压缩码加法运算后,做十进制调整;

INC(Increment) 自增;(有INC DPTR这条指令)

DEC(Decrement) 自减;(没有DEC DPTR这条指令)

MUL(Multiplication、Multiply) 乘法;(积的高8位放入B中,低8位放入A中)

DIV(Division、Divide) 除法; (商放在A中,余数放在B中)

3.逻辑运算类

ANL(AND Logic) 按位与

ORL(OR Logic) 按位或;

XRL(Exclusive-OR Logic) 按位异或;

CLR(Clear) 清零;

CPL(Complement) 取反;

下面这5条指令的操作数只能是A。

RL A(Rotate left) 循环左移;

RLC A(Rotate Left throught the Carry flag) 带进位循环左移;

RR A(Rotate Right) 循环右移;

RRC A(Rotate Right throught the Carry flag) 带进位循环右移;

SWAP A(Swap) 低4位与高4位交换;

4.控制转移类

ACALL(Absolute subroutine Call)子程序绝对调用;

LCALL(Long subroutine Call)子程序长调用;

RET(Return from subroutine)子程序返回;

RETI(Return from Interruption)中断服务子程序返回;

SJMP(Short Jump)短转移;

AJMP(Absolute Jump)绝对转移;

LJMP(Long Jump)长转移;

CJNE (Compare Jump if Not Equal)比较不相等则转移;

DJNZ (Decrement Jump if Not Zero)减1后不为0则转移;

(INTEL他妈的为什么不把字节指令和位指令做成一致的规律)

JZ (Jump if Zero)A的结果为0则转移;

JNZ (Jump if Not Zero)A结果不为0则转移;

JC (Jump if the Carry flag is set)C为1则转移;

JNC (Jump if Not Carry)C为0则转移;

JB (Jump if the Bit is set)位为1则转移;

JNB (Jump if the Bit is Not set)位为0则转移;

JBC(Jump if the Bit is set and Clear the bit)位为1则转移,并清除该位;

NOP (No Operation) 空操作;

5.位操作指令

CLR (Clear)位清零;

SETB(Set Bit) 置位1

汇编语言是由指令和伪指令一起构成的。下面给出常用的伪指令

8种常用伪指令

1.ORG 16位地址;

此指令用在原程序或数据块的开始,指明此语句后面目标程序或数据块存放的起始地址.

2.[标号:] DB 字节数据项表;

将项表中的字节数据存放到从标号开始的连续字节单元中。例如:SEG: DB 88H,100,“7”,“C”

3.[标号:]DW 双字节数据项表;

定义16位地址表,16地址按低位地址存低位字节,高位地址存高位字节。

例如:TAB: DW 1234H,7BH

4.名字 EQU 表达式 或名字=表达式;

用与给一个表达式赋值或给字符串起名字。之后名字可用做程序地址,数据地址或立即数地址使用。名字必须是一字母开头的字母数字串。

例如:COUNT=10 或 SPACE EQU 10H5.名字 DATA 直接字节地址;

给8位内部RAM单元起个名字,名字必须是一字母开头的字母数字串。同一单元可起多个名字。

例如:ERROR DATA 80H

6.名字 XDATA 直接字节地址;

给8位外部RAM起个名字,名字规定同DATA伪指令。

例如:IO_PORT XDATA 0CF04H

7.名字 BIT 位指令;

给一可位寻址的位单元起个名字,规定同DATA伪指令。

例如:SWT BIT 30H

8.END;

指出源程序到此结束,汇编对其后的程序语句不予理睬。源程序只在主程序最后使用一个END。

8051单片机彻底研究(基础篇)

需要PDF文件书的联系我

第1章单片机的来龙去脉.................................................................2

1-1单片机从头说起.....................................................................2

1-2单片机与个人电脑的比较............................................................2

1-3典型的单片机应用系统.................................................................4

1-4最简化的单片机系统...........................................................................5

1-5单片机开发的实际问题.................................................................7

1-6本书的单片机学习环境....................................................................8

第2章8051单片机简介..............................................................12

2-1微型控制器与微型处理器................................................................12

2-2时势造英雄:MCS-51系列单片机..................................................12

2-38051单片机功能方框图...............................................................14

2-48051系统复位分析...................................................................20

习题.............................................................................................22

第3章单片机的汇编语言....................................................................26

3-18051单片机的程序设计..............................................................26

3-2写汇编程序的预备知识................................................................26

3-3汇编语言的基本架构.................................................................27

3-4写汇编语言前:熟悉寄存器与指令..............................................28

3-5试写一个8051汇编程序..............................................................30

3-6配合示波器做汇编语言的除错......................................................31

3-7更进一步的8051汇编程序.........................................................33

3-88051的反汇编程序....................................................................34

习题............................................................................................34

第4章8051的存储器...........................................................................36

4-18051内部存储器的分配.................................................................36

4-2程序存储器空间..............................................................................37

4-3外部数据存储器空间.....................................................................37

4-4内部数据存储器空间.............................................................38

习题...........................................................................................39

第5章8051指令的寻址模式..............................................................42

5-18051执行指令的过程...............................................................42

5-28051的直接寻址模式............................................................45

5-38051的间接寻址模式...................................................................46

5-48051的寄存器寻址模式...............................................................47

5-58051的立即寻址模式.....................................................................49

5-68051的索引寻址模式....................................................................49

习题..............................................................................................51

第6章 8051指令说明..........................................................................54

6-18051指令格式.................................................................................54

6-28051指令概述.................................................................................54

6-38051指令集整理.......................................................................56

6-4影响标志位的指令.................................................................58

6-58051指令解析一:算术运算指令....................................................59

6-68051指令解析二:逻辑运算与移位指令..........................................62

6-78051指令解析三:数据传送指令.....................................................64

6-88051指令解析四:布尔变量操作指令................................................68

6-98051指令解析五:程序分支指令......................................................69

习题.....................................................................................75

第7章8051单片机的引脚说明.............................................................78

7-18051单片机的引脚...................................................................78

7-2认识AT89C2051........................................................................81

7-38051与AT89C2051的差异...........................................................84

7-4AT89C系列的下一步..............................................................84

习题.............................................................................................8.6

第8章8051基本程序练习..................................................................88

8-1工具的准备............................................................................88

8-28051汇编程序X8051与LINK4的操作................................................89

8-3基础范例一:LED的亮与灭.........................................................90

8-4基础范例二:蜂鸣器的使用.........................................................92

8-5基础范例三:指示灯...................................................................93

8-6基础范例四:七段显示器的使用..................................................95

8-7基础范例五:按键的使用............................................................99

习题.......................................................................................102

第9章8051控制板线路说明..............................................................104

9-1如何选用控制板......................................................................104

9-2AT2051控制板的特点..............................................................105

9-3线路分析.................................................................................105

9-4AT2051控制板的应用与学习方向..................................................108

9-5AT2051元件表及元件照片.........................................................110

9-6组装指南.............................................................................112

9-7组装的测试步骤...................................................................113

第10章8051定时/计数彻底研究......................................................124

10-1什么是定时/计数................................................................124

10-28051定时器和计数器安排......................................................124

10-3定时/计数器相关的寄存器.......................................................125

10-48051的Timer定时/计数器设置步骤...............................................127

10-5 Timer模式0彻底研究...........................................................128

10-6Timer模式1彻底研究..............................................................130

10-7 Timer模式2彻底研究.........................................................137

10-8 Timer模式3彻底研究.........................................................138

10-98051Timer模式3的再探讨.....................................................139

第11章8051中断彻底研究.........................................................142

11-1为何要有中断...............................................................142

11-28051的中断................................................................142

11-5中断的寄存器(IE和IP)的介绍..........................................146

11-68051的中断源彻底研究..........................................................148

11-78051的中断设置步骤............................................................150

11-8AT2051控制板在中断上的安排................................................151

11-9内部计数器0中断程序范例.......................................................151

11-10外部负边沿中断INTO程序范例.............................................157

11-11外部低电平中断程序范例.................................................160

11-12串行传输中断程序范例.....................................................162

习题.........................................................................................168

第12章8051串行通信彻底研究(一).............................................170

12-1为何要通信....................................................................170

12-2如何进行串行通信......................................................171

12-3RS232C的规格...............................................................173

12-48051的串行接口概述..........................................................175

12-5申行传输控制有关的寄存器:SCON.............................................177

12-68051串行传输的波特率设置.....................................................178

12-7串行传输模式0彻底研究..................................................179

12-8串行传输模式1彻底研究.......................................................184

12-9串行传输模式2彻底研究......................................................188

12-10串行传输模式3彻底研究...................................................191

第13章8051串行通信彻底研究(二).................................................196

13-18051的多处理器通信彻底研究......................................................196

13-2AT2051的串行硬件线路分析.........................................................199

13-3AT2051控制板如何与PC连接....................................................200

13-4多处理器通信的写法分析.........................................................201

13-58051串行接口发送硬件分析.....................................................202

13-6串行传输实用程序范例............................................................205

13-7串行传输的应用与影响..........................................................207

习题...........................................................................................208

进阶练习篇

第14章 AT2051进阶练习(一).......................................................210

14-1练习:蜂鸣器的控制................................................................210

14-2练习:中断服务程序所占用的时间..............................................213

14-3练习:七段显示器的初步使用....................................................215

14-4练习:ACC值的转换与显示.......................................................218

14-5练习:BCD值的转换与显示...................................................221

14-6练习:按键操作的确认.............................................................224

14-7练习:学习波形Duty Cycle的计算与显示......................................227

14-8练习:学习温度值的换算与显示...................................................227

14-9练习:温度值每秒读取两次的写法...............................................228

14-10练习:另一种温度测量的写法..................................................229

习题...........................................................................................230

第15章AT2051进阶练习(二)...............................................................234

15-1练习:启动RS485串行通信接口.................................................234

15-2练习:练习温度值转成ASCIⅡ字符串的写法.......................................235

15-3练习:串行传输的写法.........................................................236

15-4练习:串行传输的写法二..........................................................237

15-5练习:将温度的精确度提高到小数点后一位...................................238

15-6练习:串行除错程序的加入.......................................................239

习题.........................................................................................240

第16章AT2051进阶练习(三)...................................................242

16-1练习:写入一个字节的数据到E'PROM 24LC16内...........................242

16-2练习:E2PROM的读回写法分析...............................................243

16-3练习:ID值读取的写法....................................................244

16-4练习:如何判断E2PROM是否存在...........................................245

16-5练习:ID值的在线更改...........................................................246

16-6练习:配合ID调用的串行通信程序........................................246

16-7练习:串行通信程序的除错....................................................247

16-8练习:RS485通信程序的完整版............................................248

第17章汇编语言的写法分析与除错.....................................................254

17-1汇编语言的难点.........................................................................254

17-2写程序的重点..............................................................................254

17-3LED除错法..................................................................................254

17-4蜂鸣器除错法...........................................................................255

17-5DISPLAY除错法.........................................................................255

17-6串行通信除错法.........................................................................256

17-7仪器协助除错法.........................................................................257

17-8高级仪器除错法...................................................................257

习题.......................................................................................258

第18章8051例程归纳整理..................................................................260

18-1清除4个内部DATA MEMORY地址.............................................260

18-2清除4个外部DATA MEMORY地址...............................................260

18-3将外部数据存储器上4个字节值存入内部数据存储器...........................261

18-4将4个内部数据值转存到外部数据存储器中......................................261

18-5内部数据存储器内4字节相加(不含正负符号)...............................262

18-6内部数据存储器的值和外部数据存储器的值相加...............................262

18-7内部数据存储器的4字节相减.....................................................263

18-8将内部数据存储器内的值取补码.................................................263

18-9对外部数据存储器做16位的加法运算.........................................264

18-10对外部存储器做减法运算.........................................................264

18-11内部数据存储器做值的比较..........................................................265

18-12外部数据存储器做整段值的比较.............................................265

18-13内部数据存储器区与累加器做比较...............................................266

18-144字节不含正负符号的乘法运算...............................................266

18-154字节不含正负符号的除法运算...................................................267

18-16对外部数据存储器内的值做异或运算产生一个校验码..........................268

18-17确认外部数据存储器(4字节)的校验码是否正确............................269

18-18在内部数据存储器内产生4个随机数..............................................269

18-19检查外部数据存储器(16位)是否为0000H.....................................270

18-20检查外部数据存储器(16位)的值是否为1000................................271

18-21检查外部数据存储器(16位)的值是否比5000大............................271

18-22将外部数据存储器(16位)值转换成6个BCD码.............................272

18-23将ACC值(<99)转换成两个BCD码..........................................273

18-24将累加器的值转换成3个BCD码...................................................273

18-25检查一段外部数据存储器(2KB)的读写功能...................................274

18-26计算2KB程序空间的校验和(CHECKSUM).......................................274

18-27清除外部数据存储器共2048个地址...............................................275

18-28将1个字节值转换成ASCⅡ码,供数据显示用..................................275

18-29将ASCII码转换成二进.制...................................................276

第19章混合式示波器的认识与使用....................................................280

19-2基本测量示范....................................................................283

19-3特殊信号测量.........................................................................285

第20章数字电表的使用...................................................................288

20-1数字电表功能..............................................................................288

20-2数字电表操作要点...................................................................288

20-3数字电表使用时的特别注意事项...................................................290

20-4AT2051控制板操作示范............................................................291

20-5电表的校正.........................................................................291

习题............................................................................................293

第21章USB烧录器的安装与使用........................................................296

21-1旗威USB烧录器....................................................................296

21-2烧录器的安装...........................................................................296

21-3烧录程序的安装....................................................................297

21-4烧录功能说明............................................................................297

21-5 Files文件菜单......................................................................299

21-6IC芯片菜单........................................................................301

21-7Programmer烧录器菜单.............................................................303

21-8Diagnostic 诊断菜单....................................................................305

21-9USB烧录器特殊用法...............................................................306

21-10USB烧录器注意事项...........................................................307

习题.......................................................................................307

附录............................................................................................309

附录AASCII表..........................................................................309

附录B8051相关IC引脚图............................................................311

附录C8051指令集总整理..................................................................314

附录D8051指令整理(按功能划分)................................................324

附录E8051指令整理(按十六进制排列)..........................................329

附录F8051SFR表与RESET后的初始值.............................................336

附录GSFR特殊功能寄存器整理表....................................................337

附录H如何购买电子元件.............................................................340

附录l如何识别晶体管(三极管)的引脚..............................................342

附录J如何看Data Sheet................................................................345

附录K如何焊接...........................................................................347

附录L如何上网找元件..............................................................349

相关问答

8051单片机 堆栈读取规则?

1.8051单片机的堆栈读取规则是按照先进后出的原则进行的。2.堆栈是一种用于存储临时数据的内存区域,它的特点是后进先出。在8051单片机中,堆栈是由两个寄存...

说明 8051单片机 内部数据储存区空间分配情况。32个通用寄存器各对应哪些RAM单元?

片内数据存储区一般指的是片内ram。内部数据存储器(片内ram)一共有256字节。这256字节被分成两半,低128字节的ram区称为用户数据ram,高128字节为sfr区,sfr区...

8051单片机 控制电路包括?

8051单片机控制电路主要包括:1、有一个CPU用来运算和控制,2、有四个并行IO口,分别是P0、P1、P2、P3,3、有ROM,用来存放程序,现在也有用flash的4、有RAM...

8051单片机 的基础知识?

谢邀。8051单片机的基础知识有:8051单片机内部资源。中央处理器、程序存储器(ROM)、数据存储器(RAM)、定时器(2个16位可编程)、四组8位IO口、一个双全工...

8051单片机 有多少个接口?

8051一般有40个接口,这里拿我们国产的具有8051核心的芯片STC89C52RC来介绍一下其接口情况。一、芯片简介TC89C52RC芯片是宏晶科技公司生产的STC89系列单片机中...

8051 和C51的区别?

8051单片机是英特尔公司推出的嵌入式微控制器(MCU),其内核就是我们所熟知的MCS-51内核。英特尔公司将MCS-51的内核出售给其公司,比如ATMEL,自己已经不生产单...

8051单片机 主要由哪几部分组成,各有什么功能?

1、中央处理器(CPU)CPU是单片机的核心,它是8位数据宽度的处理器,能处理8位二进制数据或代码其主要任务是负责控制、指挥和调度整个系统协调工作,完成运算和...

8051单片机 有哪五个中断源?

最基本型的51单片机有外部中断0、外部中断1、定时计数器t0/t1、串口通讯等五个中断源。这种最基本型的8051单片机早就被淘汰了,或者不再使用,取而代之的是扩...

8051单片机 有几个16位计数器其中寻址范围是?

8051单片机有两个16位计数器,分别为Timer0和Timer1。这两个计数器有着不同的寻址范围,Timer0的寻址范围为0000H到FFFFH,而Timer1的寻址范围为0000H到FFFFH。通...

8051单片机 的中断系统哪四个部分组成?

51单片机有5个中断源,两个中断优先级:INT0、T0、INT1、T1、串行口中断(包括串行接收中断RI和串行发送中断TI)。这5个中断源的中断入口地址分别...

猜你喜欢