51汇编语言程序设计.pdf
《51汇编语言程序设计.pdf》由会员分享,可在线阅读,更多相关《51汇编语言程序设计.pdf(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第四章 MCS-51汇编语言程序设计重点及难点:单片机汇编语言程序设计的基本概念、伪指令、单片机汇编语言程序的三种基本结构形式、常用汇编语言程序设计。教学基本要求:1、掌握汇编语言程序设计的基本概念;2、掌握伪指令的格式、功能和使用方法;3、掌握顺序结构、分支结构和循环结构程序设计的步骤和方法;4、掌握常用汇编语言程序设计步骤和方法。教学内容4.1汇编语言程序设计概述一、汇编语言的特点(1)助记符指令和机器指令一一对应,所以用汇编语言编写的程序效率高,占用存储空间小,运行速度快,因此汇编语言能编写出最优化的程序。(2)使用汇编语言编程比使用高级语言困难,因为汇编语言是面向计算机的,汇编语言的程
2、序设计人员必须对计算机硬件有相当深入的了解。(3)汇编语言能直接访问存储器及接口电路,也能处理中断,因此汇编语言程序能够直接管理和控制硬件设备。(4)汇编语言缺乏通用性,程序不易移植,各种计算机都有自己的汇编语言,不同计算机的汇编语言之间不能通用;但是掌握了一种计算机系统的汇编语言后,学习其他的汇编语言就不太困难了。二、汇编语言的语句格式:;三、汇编语言程序设计的步骤与特点(1)建立数学模型(2)确定算法(3)制定程序流程图(4)确定数据结构(5)写出源程序(6)上机调试程序4.2伪 指 令伪指令是程序员发给汇编程序的命令,也称为汇编命令或汇编程序控制指令。MCS-51 常见汇编语言程序中常用
3、的伪指令:第四章MCS-51 汇编语言程序设计91 1ORG(ORiGin)汇编起始地址命令 ORG 2END(END of assembly)汇编终止命令 END 3EQU(EQUate)赋值命令 EQU 4DB(Define Byte)定义字节命令 DB 5DW(Define Word)定义数据字命令 DW 6DS(Define Stonage)定义存储区命令 DW 7BIT 位定义命令 BIT 8DATA 数据地址赋值命令 DATA 4.3单片机汇编语言程序的基本结构形式一、顺序程序例 4-1 三字节无符号数相加,其中被加数在内部RAM 的 50H、51H 和 52H 单元中;加数在内部
4、RAM 的 53H、5414和 55H 单元中;要求把相加之和存放在50H、51H 和 52H 单元中,进位存放在位寻址区的00H 位中。MOV R0,#52H;被加数的低字节地址MOV R1,#55H;加数的低字节地址MOV A,R0 ADD A,R1;低字节相加MOV R0,A;存低字节相加结果DEC R0 DEC R1 MOV A,R0 ADDC A,R1;中间字节带进位相加MOV R0,A;存中间字节相加结果DEC R0 DEC R1 MOV A,R0 ADDC A,R1;高字节带进位相加MOV R0,A;存高字节相加结果CLR A 文档编码:CT8M8K8R1E3 HI6N10X5T
5、4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2
6、F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K
7、8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X
8、5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6
9、T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M
10、8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N1
11、0X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2ADDC A,#00H;存放进位的单元地址MOV R0,A;进位送 00H 位保存二、分支程序1单分支程序例 4-2 变量 X 存放在 VAR 单元内,函数值Y 存放在 FUNC 单元中,试按下式的要求给 Y 赋值。010001XXXY本题的程序流程见图4-1(a)。参考程序:ORG 1000H VAR DATA
12、30H FUNC DATA 31H MOV A,VAR;A XJZ DONE;若 X=0,则转 DONE JNB ACC.7,POSI;若 X0,则转 POSI MOV A,#0FFH;若 X0,则 Y=1 DONE:MOVE FUNC,A;存函数值SJMP$END 图 4-1 例 4-2的分支流程图文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T
13、4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2
14、F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K
15、8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X
16、5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6
17、T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M
18、8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N1
19、0X5T4M5 ZA6S4H6T2F2第四章MCS-51 汇编语言程序设计93 这个程序的特征是先比较判断,然后按比较结果赋值,这实际是三分支而归一的流程图,因此,至少要用两个转移指令。初学者很容易犯的一个错误是:漏掉了其中的SJMP DONE语句,因为流程图中没有明显的转移痕迹。这个程序也可以按图4-1(b)的流程图来编写,其特征是先赋值,后比较判断,然后修改赋值并结束。参考程序:ORG 1000H VAR DATA 30H FUNC DATA 31H MOV A,VAR;A X JZ DONE;若 X=0,则转 DONE MOV R0,#0FFH;先设 X0,R0=FFH JNB ACC.
20、7,NEG;若 X0,R0=1 NEG:MOV A,#01H;若 X0,则 Y=1 DONE:MOV FUNC,A;存函数值SJMP$END 2多分支程序图 4-2 多分支程序转移三、循环程序循环程序一般由4 部分组成:(1)置循环初值,即确立循环开始时的状态。(2)循环体(工作部分),要求重复执行的部分。(3)循环修改,循环程序必须在一定条件下结束,否则就要变成死循环。(4)循环控制部分,根据循环结束条件,判断是否结束循环。以上 4 个部分可以有两种组织方式。例 4-3 从 BLOCK 单元开始存放一组无符号数,一般称为一个数据块。数据块长度放在 LEN 单元,编写一个求和程序,将和存入SU
21、M 单元,假设和不超过8 位二进制数。在置初值时,将数据块长度置入一个工作寄存器,将数据块首地址送入另一个工作寄存器,一般称它为数据块地址指针。每做一次加法之后,修改地址指针,以便取出下一个数来相加,并且使计数器减1。到计数器减到0 时,求和结束,把和存入SUM 即可。文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文
22、档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1
23、E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4
24、M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F
25、2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8R1E3 HI6N10X5T4M5 ZA6S4H6T2F2文档编码:CT8M8K8
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 51 汇编语言 程序设计
限制150内