汇编语言课设文本编辑器_第1页
汇编语言课设文本编辑器_第2页
汇编语言课设文本编辑器_第3页
免费预览已结束,剩余57页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、汇编语言课程设计说明书学院:软件学院专业:软件工程学生姓名:马江涛学 号:题目文本编辑器指导教师:陈够喜潘广贞杨剑马巧梅2016年1 月目录摘要一、课程设计的目的1. 1设计的目的1.2 设计的内容二、设计方案的论证 2.1开发背景-2 -1 -1 -1 -2 -2 -2 -2.3设计思路错误!未定义书签2.2程序设计的意义三、 设计的实现过程 -3 -3.1总体设计方案 -3 -3.2实现过程 -3 -3.3 数据定义 -4 -3.4 模块设计 -6 -四、调试运行及结果分析 -9 -4.1 运行结果 -9 -4.2 结果分析 -12 -五、 测试及问题探讨 -13 -5.1 程序测试 -1

2、3-六、课设总结与体会 -16-七、参考文献 -17-附录 -18-文本编辑器在我们的日常生活中使用非常频繁,是我们工作当 中不可或缺的工具。我们经常使用的文本编辑器有微软的记事本和 Microsoft Word。但是本次课程设计我使用了 8086汇编语言实现 了 DOST的简易文本编辑器,虽然与平时使用的文本编辑器相比功 能比较简单,也不够完善。但是旨在考察汇编语言的运用以及软件 的实现过程。本次设计以设计思路为主介绍简易文档编辑器的设计实现程, 对其设计原理进行一定的阐述,并且分模块对其中较为重要的 子程序进行讲解,并且附上运行结果及汇编源程序。关键字:文本编辑器、汇编语言、 DOS、课程

3、设计的目的1.1 设计的目的掌握汇编语言的使用,掌握 BIOS DOS功能调用的使用方法,以及对汇编语言程序设计的过程有较深刻的理解。1.2 设计的内容本次设计主要包括一下内容:1. 美观且易于操作的界面;2. 在文本编辑区可以随意输入字符;3. 可以使用Backspace键对光标的前一个字符删除;4. 实现了光标上移、下移、左移、右移;5. 实现了下拉菜单以及弹出式菜单;6. 可以实现屏幕的上卷和下卷;二、设计方案的论证2.1开发背景本次开发主要是在微机原理与接口技术这门课学习完成之 后,通过做一些实用的小软件考察自己的学习情况。并且熟悉汇编 语言开发程序的过程。2.2程序设计的意义由于信息

4、化的普遍,所以文本编辑器在我们工作中也是必不可 少的,所以我选择了开发文本编辑器,不只为人们带来了便利,同 时也能锻炼自己开发思路,熟悉汇编语言开发过程,以及提高软件 开发水平。常见的有 Windows下的记事本,MacOSX下的文本编辑,Linux 下的vi、emacs gedit、DOS下的edit等。本次设计类似于 DOS 下的edit。2.3设计思路本程序主要利用BIOS功能调用设计编辑器的菜单和编辑窗口, 以及光标的定位与获取。利用DO砂能调用实现字符的读取与输出, 以及对按键的识别。通过对光标以及字符输出来控制删除以及上下 左右键的控制。三、设计的实现过程3.1总体设计方案程序利用

5、模块化设计方法,对每个要实现的功能都设计成子程 序,方便使用。程序中具体模块如图 3-1 o图3-1程序关系3.2实现过程程序通过对BIOS和DOS勺功能调用实现了对窗口、菜单、字符 输入输出、按键识别等功能。程序整体利用了模块化的程序设计方 法,把每个功能模块都分成子程序来分别调用。程序中主要用到了 以下子程序:display(显示菜单栏);dis_edit(显示编辑窗口 );dis_file( 显示文件菜单);dis_text( 显示文本菜单);key_back(backspace 删除字符); key_down(光标向下); key_left(光标向左); key_up(光标向上);ke

6、y_right(光标向右); key_pgup(菜单的循环选择); ok_exit(退出);open(子菜单显示及控制);3.3数据定义程序中要显示的字符串都事先在数据段DS和附加段ES中定义好了,由于功能调用的需要所以把数据定义在了数据段和附加段 中。以下是程序中用到数据的定义:data segme nts db 'File View Text About$'f1 db 'Ope n' ,10,13,'Exit',10,13,'$'f2 db 'Clear$'i db 0b db 0buff db 1200 du

7、p(?),'$'printf db "Can't ope n the File$"mss db 'Massage$'ab1 db 'About Edit$'ab2 db 'GaoHaiFe ng$'ab3 db 'C1141$'ab4 db '2013-6-22$'q1 db '543589796$'data ends eata segme ntsi db 'File$'s2 db 'View$'s3 db 'Tex

8、t$'s4 db 'About$'s5 db 'Ope n$'s6 db 'Exit$'s7 db 'Clear$' eorr db 'eorr:$'ok db 5bh,'OK',5dh,'$' desig n db 'Desig n:$' class db 'Class:$' date db 'Date:$' qq db 'QQ:$'eata ends事先定义好数据的结构可以减少程序设计中很多的麻烦3.4模块设

9、计341绘制界面个是编辑区,主要利用了 BIOS功能调用绘制了两个窗口, 个是菜单栏。实现过程见图3-4-1 o图3-4-1绘制界面342检测按键这个模块主要是利用了 AL=O, INT 16H来实现的,其中AH中存 放的是按键的扫描码,AL中存放的是按键的ascii码。具体实现过 程见图3-4-2 。图3-4-2 检测按键343子菜单绘制该模块同样采用了 BIOS功能调用设置子菜单,具体操作见图343。开始绘制File子菜单图3-4-3绘制子菜单四、调试运行及结果分析4.1 运行结果程序的主界面,包含有File , View, Text, About菜单,如图4-1所示。图4-1程序主界面按

10、下PgUp键对菜单进行循环选择,绿色光带显示当前选中菜单, 按任意除PgUp之外的按键切换到编辑区,如图 4-2所示。图4-2选择菜单File菜单包括Open和Exit子菜单,如图4-3所示图4-3下拉菜单-10 -当光带选中Open或者Exit时按下回车键,将执行光带所选中的子菜单项所对应的程序,图中为选中Open,如图4-4所示。图4-4选择OpenText菜单下只有一个Clear,用来清屏,如图4-5所示图4-5 text子菜单-11 -About主要用来显示作者以及开发的相关信息,如图4-6.图4-6选中About4.2 结果分析本程序主要仿照DOS下的Edit文本编辑器,但是由于时间

11、的 关系有些功能未实现,主要实现了菜单的弹出、选择、光标的移动、 文本的删除、屏幕上卷等功能。-12 -五、测试及问题探讨5.1程序测试首先是测试文本编辑区,如图5-1.图5-1编辑测试然后是测试菜单弹出后文本区的内容是否被抹掉,如图5-2和-13 -5-3所示。图5-2文本区保存图5-3文本区回复接下来是测试清屏菜单项,如图5-4和5-5所示-14 -图5-4选中Clear图5-5文本清屏-15 -六、课设总结与体会通过本次课程设计可以说收获颇多,虽然在程序设计的过程中 遇到很多问题,其中想过放弃,也曾因此彻夜不眠过,甚至有思路 就立马把程序写出来。但最终都在老师的帮助和自己的努力下走过 来

12、了。做完了这个程序之后感觉对汇编的理解更加深刻了,也似乎 懂得了开发底层软件的原理。虽然汇编和其它程序设计语言相比麻 烦很多,但是汇编是通过对计算机底层硬件的控制来达到人机交互 的效果或者是实现了人们需要的功能。可以说了解了计算机大体的 工作过程,为以后学习嵌入式系统以及计算机底层方面做了铺垫。-16 -七、参考文献1 吕林涛微型计算机原理与接口技术科学出版社.2011年5月2 王延松.微机原理与接口技术实践教程.2011年9月3 沈美明.IBM-PC汇编语言程序设计清华大学出版社.2001年8 月-17 -附录源程序:data segme nts db 'File View Text

13、 About$'fl db 'Ope n',10,13,'Exit',10,13,'$'f2 db 'Clear$'i db 0b db 0buff db 1200 dup,'$'printf db "Can't ope n the File$" mss db 'Massage$' ab1 db 'About Edit$' ab2 db 'GaoHaiFe ng$' ab3 db 'C1141$'ab4 db 

14、9;2013-6-22$' q1 db '543589796$' data endseata segme nts1 db 'File$'s2 db 'View$'s3 db 'Text$'s4 db 'About$'s5 db 'Ope n$'s6 db 'Exit$'s7 db 'Clear$'eorr db 'eorr:$'ok db 5bh,'OK',5dh,'$' desig n db 'Desi

15、g n:$' class db 'Class:$' date db 'Date:$' qq db 'QQ:$'-18 - eata endsstack segme ntdw 1000 dupstack endscode segme ntassume ds:data,cs:code,ss:stack,es:eata sta rt:mov ax,datamov ds,axmov ax,eatamov es,axmov ah,0mov al,3int 10hcall display;显示菜单栏call dis_edit;显示编辑区mov ah,

16、4chint 21hdisplay proc near;显示菜单栏mov ah,6mov al,0mov ch,0mov cl,0mov dh,0mov dl,79mov bh,70hint 10hmov ah,6mov al,1mov ch,0mov cl,0mov dh,0 mov dl,79-19 -mov bh,70hint 10hmov ah,2 mov bh,0 mov dh,0 mov dl,0 int 10hmov ah,09h lea dx,sint 21hretdisplay endpdis_edit proc near;显示编辑区mov di,0 ;作为缓存指针mov a

17、h,6mov al,0mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10hmov ah,6mov al,1mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10h-20 -Pgup_r: mov ah,2 mov bh,0 mov dh,1 mov dl,0 int 10hn extl:mov cx,80next:mov ah,00h;从键盘读取字符int 16hcmp al,1bh ;判断输入的字符是否是ESCjz exitcmp al,0dh ;判断输入的字符是否是回车jz en tercmp

18、ah,48h ;判断按键是否是上,ah中存放的是特殊键盘扫描码jz di_upcmp ah,4bh;判断是否是左jz di_leftcmp ah,4dh ;判断是否是右jz di_rightcmp ah,50h ;判断是否是下jz di_dow ncmp ah,49h ;判断是否是 pgup键按下jz di_pgupcmp ah,0ehjz di_backmov buffdi,al ;每次接收一个字符时都存放到BUFF中inc dimov buffdi,'$'mov dl,al ;al中存放的是普通字符的ascii码mov ah,2int 21hloop nextjmp nex

19、t1;这里相当于无限循环,CX的值不起作用en ter:mov buffdi,10-21 -inc dimov buff di,13inc dimov ah,3 ;获取光标位置mov bh,0int 10hcmp dh,24;判断回车之后是否是行尾jz go_aga inmov ah,2mov bh,0inc dhmov dl,0int 10hjmp n extldi_up:call key_up ;这里不需要重新定义CX的值,程序会自动换行;调用左移子程序调用右移子程序;调用下移子程序;调用pgup子程序;上卷一行定位到行尾jmp n ext1 di_left:call key_leftjm

20、p n ext1 di_right:call key_right ;jmp n ext1di_dow n: call key_dow n jmp n ext1 di_pgup:call key_pgup jmp pgup_rdi_back:call key_back jmp n ext1go_aga in:call dis_loop jmp n ext1exit:mov ah,6mov al,0 mov ch,0 mov cl,0 mov dh,24 mov dl,79-22 -int 10hret dis_edit endpdis_loop proc near;编辑区上卷一行光标定位至U行尾

21、mov ah,6mov al,1mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10hmov ah,2mov bh,0mov dh,24mov dl,0int 10hretdis_loop endpkey_up proc n earmov ah,3 ;读取光标位置mov bh,0int 10hcmp dh,1jz rodow nmov ah,2 ;定位光标位置dec dhint 10hreturn: ret-23 -rodow n: call roll_dow njmp returnkey_up endproll_dow n proc n ear

22、 ;屏幕下卷mov ah,7mov al,1mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10hmov ah,3 ;读取光标位置mov bh,0int 10hmov ah,2 ;定位光标位置int 10hretroll_dow n endpkey_left proc n earmov ah,3 ;读取光标位置mov bh,0int 10hcmp dl,0;判断是否到了第一列jz go_left;是的话移到上一行行尾mov ah,2mov bh,0dec dlint 10h-24 -jmp retl go_left:cmp dh,1 jnz ro

23、ll_up mov ah,6 mov al,1 mov ch,1 mov cl,0 mov dh,24 mov dl,79 mov bh,1eh int 10h mov ah,2 mov bh,0 mov dl,79 mov dh,1 int 10h jmp retl roll_up:mov ah,2;移到上一行行尾mov bh,0 dec dh mov dl,79 int 10h retl:retkey_left endp key_right proc n earmov ah,3 ;读取光标位置mov bh,0int 10hcmp dl,79jnz go_rightcmp dh,24jnz

24、on_okmov ah,6mov al,1-25 -mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10hmov ah,2mov bh,0mov dh,24mov dl,0int 10hjmp ret2 on _ok:mov ah,2mov bh,0inc dhmov dl,0 int 10h jmp ret2 go_right: mov ah,2mov bh,0inc dlint 10h ret2:retkey_right endp key_dow n proc n earmov ah,3 mov bh,0 int 10hcmp dh,24 j

25、nz m_dow n mov ah,6mov al,1mov ch,1mov cl,0-26 -mov dh,24mov dl,79mov bh,1ehint 10hmov ah,3mov bh,0int 10hmov ah,2mov bh,0mov dh,24int 10hjmp ret3m_dow n: mov ah,2mov bh,0inc dhint 10hret3:retkey_dow n endpkey_pgup proc near;按下 pgup 键的处理过程st_pgd n: call displaycmp i,0jnz nt ;判断当前的菜单项是第几个mov ah,6 ;菜单

26、项处清屏mov al,0mov bh,1fhmov ch,0mov cl,0mov dh,0mov dl,3int 10hmov ah,13h ;bios 输出字符串-27 -mov al,0mov cx,4mov dh,0mov dl,0mov bl,0a5hmov bh,0lea bp,s1int 10hjmp retOnt: cmp i,1jnz nt1mov bh,1fhmov ah,6mov al,0mov ch,0mov cl,9mov dh,0mov dl,12int 10hmov ah,13h ;bios 输出字符串mov al,0mov cx,4mov dh,0mov dl,

27、9mov bl,0a5hmov bh,0lea bp,s2int 10hjmp ret0nt1:cmp i,2jnz nt2-28 -mov bh,1fh mov ah,6 mov al,0 mov ch,0 mov cl,18 mov dh,0 mov dl,21 int 10hmov ah,13h mov al,0 mov cx,4 mov dh,0 mov dl,18 mov bl,0a5h mov bh,0 lea bp,s3 int 10hjmp retOnt2:cmp i,3jnz nt1mov bh,1fhmov ah,6 mov al,0 mov ch,0 mov cl,27

28、mov dh,0 mov dl,30 int 10hmov ah,13h mov al,0 mov cx,5 mov dh,0;小菜单清屏;bios输出字符串;bios输出字符串-29 -mov dl,27 mov bl,0a5h mov bh,0 lea bp,s4int 10hretO:inc irtt:cmp i,4jnz rttmov i,0mov ah,0hint 16hlol:cmp ah,49hjz st_pgd ncmp al,0dh ;判断是否是回车jnz rt0cmp i,0jnz lolcall dis_aboutjmp rt0cmp i,1jnz qqqcall dis

29、_filejmp rt0qqq:cmp i,3rt0:jnz rtt ;不确定call dis_textcmp i,1jnz ntf-30 -mov ah,6 ;菜单项处清屏mov al,0mov bh,70hmov ch,0mov cl,0mov dh,0mov dl,3int 10hmov ah,13h ;bios 输出字符串mov al,0mov cx,4mov dh,0mov dl,0mov bl,70hmov bh,0lea bp,s1int 10hntf:jmp rrrcmp i,2jnz ntflmov bh,70hmov ah,6mov al,0mov ch,0mov cl,9

30、mov dh,0mov dl,12int 10hmov ah,13h ;bios 输出字符串mov al,0mov cx,4mov dh,0-31 -mov dl,9mov bl,70hmov bh,0lea bp,s2int 10hjmp rrr ntfl:cmp i,3jnz ntf2mov bh,70hmov ah,6 ;小菜单清屏mov al,0mov ch,0mov cl,18mov dh,0mov dl,21int 10hmov ah,13h ;bios 输出字符串mov al,0mov cx,4mov dh,0mov dl,18mov bl,70hmov bh,0lea bp,s

31、3int 10hjmp rrrn tf2:cmp i,0jnz rrrmov bh,70hmov ah,6mov al,0mov ch,0-32 -mov cl,27mov dh,0mov dl,30int 10hmov ah,13h ;bios 输出字符串mov al,0mov cx,5mov dh,0mov dl,27mov bl,70hmov bh,0lea bp,s4int 10hrrr:mov i,0retkey_pgup endpdis_file proc near;显示 File 菜单mov ah,6mov al,0mov bh,70hmov ch,1mov cl,0mov dh

32、,2mov dl,6int 10hmov ah,6mov al,1mov bh,70hmov ch,1mov cl,0mov dh,2mov dl,6int 10h-33 -mov ah,2mov bh,0mov dh,1mov dl,0int 10hmov ah,09hlea dx,f1int 21hmov ah,00hint 16hcmp ah,50h;如果按方向键下jnz in putan_don: cmp b,0jnz hahamov ah,13hlea bp,s6mov al,0mov cx,4mov dh,2mov dl,0mov bh,0mov bl,70hint 10hmov

33、ah,13hlea bp,s5mov al,0mov cx,4mov dh,1mov dl,0mov bh,0-34 -mov bl,05ahint 10hjmp in puthaha:cmp b,1jnz in putmov ah,13hlea bp,s5mov al,0mov cx,4mov dh,1mov dl,0mov bh,0mov bl,70hint 10hmov ah,13hlea bp,s6mov al,0mov cx,4mov dh,2mov dl,0mov bh,0mov bl,05ahint 10hin put:inc bcmp b,2jnz eeemov b,0eee:

34、mov ah,00int 16hcmp ah,50h ;判断是否是方向键下jz an_doncmp ah,01h;判断是否是ESCjz rrr1-35 -cmp al,Odh ;判断是否是回车 jnz eeecmp b,1jnz cexit call ope n jmp rrrl cexit:call ok_exitrrrl:mov ah,6mov al,0mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10hmov ah,6mov al,1mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10hca

35、ll dis_buffretdis_file endp dis_buff proc n earmov ah,2mov bh,0mov dh,1mov dl,0int 10hmov ah,9-36 -lea dx,buffint 21hretdis_buff endpope n proc n earcall displaymov ah,6mov al,0mov ch,1mov cl,0mov dh,24mov dl,79mov bh,1ehint 10hcall dis_buff;显示缓存数据mov ah,6mov al,0mov bh,70hmov ch,6mov cl,19mov dh,6m

36、ov dl,59int 10hmov ah,6 ;弹出窗口 message显示区mov al,1mov bh,70hmov ch,6mov cl,19mov dh,6mov dl,59int 10h-37 -mov ah,2mov bh,0mov dh,6mov dl,34int 10hmov ah,9lea dx,mssint 21hmov ah,6mov al,0mov bh,5ehmov ch,7mov cl,19mov dh,14mov dl,59int 10hmov ah,6mov al,1mov bh,5ehmov ch,7mov cl,19mov dh,14mov dl,59in

37、t 10hmov ah,13h ;显示 eoorlea bp,eorrmov al,0mov cx,5mov bh,0mov bl,52hmov dh,10mov dl,24-38 -int 10hmov ah,2mov bh,0mov dh,1Omov dl,32int 10hmov ah,9 lea dx,pri ntf int 21hmov ah,13h lea bp,ok mov al,0 mov cx,4 mov bh,0 mov bl,70h mov dh,12 mov dl,37 int 10hsure:mov ah,00hint 16hcmp al,0dh jnz sure m

38、ov ah,6 mov al,0 mov ch,1 mov cl,0 mov dh,24 mov dl,79 mov bh,1eh int 10hcall dis_buff ret-39 -ope n endp ok_exit proc procmov ah,6 mov bh,0 mov al,0 mov ch,0 mov cl,0 mov dh,24 mov dl,79 int 10hmov ah,4ch int 21hret ok_exit endp dis_text proc n earmov ah,6mov al,0mov bh,70h mov ch,1 mov cl,18 mov d

39、h,1 mov dl,24 int 10hmov ah,6mov al,1 mov bh,70h mov ch,1 mov cl,18 mov dh,1 mov dl,24 int 10h-40 -mov ah,2mov bh,0mov dh,1mov dl,18int 10hmov ah,09h lea dx,f2 int 21hmov ah,13h lea bp,s7 mov al,0 mov cx,5 mov dh,1 mov dl,18 mov bh,0 mov bl,05ah int 10hin puu:mov ah,0int 16hcmp ah,01h jz r121cmp al,

40、0dh jnz r121 mov buff,'$' r121:mov ah,6mov al,0 mov ch,1 mov cl,0 mov dh,24 mov dl,79 mov bh,1eh int 10h-41 - call dis_buff retdis_text endp dis_about proc n earmov ah,6mov al,0mov bh,70hmov ch,6mov cl,19mov dh,6mov dl,59int 10hmov ah,6mov al,1mov bh,70hmov ch,6mov cl,19mov dh,6mov dl,59int

41、10hmov ah,2mov bh,0mov dh,6mov dl,34int 10hmov ah,9 ;输出 About Edit lea dx,ab1 int 21hmov ah,6mov al,0-42 -mov bh,3ehmov ch,7mov cl,19mov dh,14mov dl,59int 10hmov ah,6mov al,1mov bh,3ehmov ch,7mov cl,19mov dh,14mov dl,59int 10hmov ah,13hlea bp,design;显示 designmov cx,7mov dh,8mov dl,30mov bh,0mov bl,3

42、0hint 10hmov ah,6 ;显示CLASS处清屏mov al,0mov bh,30hmov ch,9mov cl,30mov dh,9mov dl,38int 10hmov ah,13hlea bp,class;显示 classmov cx,5-43 -mov dh,9mov dl,30mov bh,0mov bl,31hint 10hmov ah,6 ;显示date处清屏mov al,0mov bh,3ehmov ch,10mov cl,30mov dh,10mov dl,38int 10hmov ah,13hlea bp,date ;显示日期mov cx,5mov dh,10mov dl,30mov b

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论