您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页汇编课程设计报告

汇编课程设计报告

来源:好走旅游网


黄冈师范学院

课程设计报告

课程名称:微机原理与汇编语言

设计题目: 打字练习程序

院 系: 计算机科学与技术学院

专 业: 计算机科学与技术

班 级: 计科0702班 姓 名: 黄亚琦

学 号: 200726140217 日 期: 09年 6 月 8 日 ~ 09年 12 月 31日 指导教师: 朱 泽 民

成 绩:

第一章 需求分析 .......................................... 1 1. 本课程设计题目 ..................................... 1 2. 本课程设计要求及任务 ............................... 1 3. 课程设计思想 ....................................... 1 4. 开发工具 ........................................... 2 第二章 概要设计 .......................................... 2 1. 分析 ............................................... 2 第三章 详细设计 .......................................... 2 1. 程序流程图 ......................................... 3 2. 软件设计程序 ....................................... 4 第四章 调试与操作说明 ................................... 14 第五章 课程设计总结与体会 ............................... 16

打字练习程序

第一章 需求分析

1. 本课程设计题目

打字练习程序

2. 本课程设计要求及任务

基本要求:

(1)实现打字练习功能; (2)有一定的图形界面; (3)能够进行成绩管理更好。

任务: 进行打字练习的程序设计,将这样的一个简单游戏用汇编语言呈现出来。

3. 课程设计思想

主函数中调用的子函数:

1. 在显示之前显示清屏调用CLEAR, 2. 用来选择难度的子函数:INPUT, 3. 若判断出错,则跳转到子函数:ERROR, 4. 游戏开始的子程序:GAME-START, 5. 控制字母落下的子程序:FALL,

第1页

打字练习程序

6. 在FALL中会调用到RANDOM,

7. 暂停,一直循环,再次输入为空格则解除暂停PAUSE, 8. 使上面一行的字符消失,其Y值增加,第二次循环的时候在下一行显示ERASE

9.

击中后处理TO_HIT.

4. 开发工具

实验程序的开发工具编辑器. 编辑器采用Masm for windows。:

第二章 概要设计

1. 分析

打字练习是一个很常见的游戏,当然会存在一个主页,即菜单。还会有游戏界面,对于游戏版块的设计,要包含打字练习和分数每当一个字母掉下时,若输入的字母正确,字母变成黄色,有响铃,且重新掉下字母,分数加一,若字母在到达底线时还没有正确的字母输入,则当字母到达底线时新的字母落下,此时分数不进行加减。

第三章 详细设计

第2页

打字练习程序

1. 程序流程图

选择难度 否 是否为1或2 Error 是 1 判断是1或2 Speed+2 2 Speed+4

Game_start fall pause 是否击中 Erase, Onfloor To_hit Print_score 第3页

打字练习程序

fall exit

2. 软件设计程序

Init_game macro x,y,letter,deta,num,sign

mov cx,00h mov dh,x mov dl,y sign: mov ah,02h

mov bh,00h int 10h

;INT 10h / AH = 0Ah - write character only at cursor position. ;input:

;AL = character to display. ;BH = page number.

;CX = number of times to write character. push cx mov ah,0ah mov al,letter mov bh,00h mov cx,01h int 10h pop cx

inc cx inc deta cmp cx,num jne sign endm

;;;;;;;;;;;;;;;;;;;;;;;;;; ;;宏清屏

;;;;;;;;;;;;;;;;;;;;;;;;;;

;int 10h\\ah=06h scroll up window

第4页

打字练习程序

;AL = number of lines by which to scroll (00h = clear entire window).

;BH = attribute used to write blank lines at bottom of window.7h=0111b light gray ;CH, CL = row, column of window''''s upper left corner. ;DH, DL = row, column of window''''s lower right corner. ;

clear_screen macro x1,y1,x2,y2 mov ah,06h mov al,00h mov bh,07h mov ch,x1 mov cl,y1 mov dh,x2 mov dl,y2 int 10h

;int 10h\\ah=02h set cursor position at (dh,dl) ;DH = row. ;DL = column.

;BH = page number (0..7). mov ah,02h mov bh,00h mov dh,00h mov dl,00h int 10h endm

;;;;;;;;;;;;;;;;;;;; SHOW macro p1,p2,p3 local Next mov ch,0 mov cl,p1 mov bx,7

mov si,offset p1 inc si

mov dh,p2 mov dl,p3

Next: mov ah,2 int 10h push cx mov cx,1 mov al,[si]

第5页

打字练习程序

mov ah,9 int 10h pop cx inc dl inc si loop Next endm

DATASEG segment

Mesg1 db 15,\" BY marsh \" Mesg2 db 15,\" No.20091001 \" Mesg4 db 11,\" Select: \"

Menu1 db 11,\" 1.Easy \" Menu2 db 11,\" 2.Hard \"

hotkey1 db 11,\"ESC to Menu\" hotkey2 db 14,\"SPACE to pause\" hotkey3 db 18,\"Any key to start!!\" let_base db \"a\"; letter db 2 dup (?) speed dw ?,800d,400d scoremsg db 6,\"SCORE:\" hit_sum db ?,0

exitmeg db 21,\"Thank you for playing\" DATASEG ENDS

STACK SEGMENT PARA STACK \"STACK\"

db 64 dup(0)

STACK ENDS

CODESEG SEGMENT

ASSUME DS:DATASEG, CS:CODESEG START:

MOV AX, DATASEG MOV DS,ax

clear_screen 00d,00d,24d,79d

;隐藏光标

第6页

打字练习程序

mov cx,0 mov ah,1

or ch,00010000b int 10h

SHOW Mesg1,11d,33d SHOW Mesg2,13d,33d mov ah,7 int 21h Menu:

clear_screen 00d,00d,24d,79d

SHOW Menu1,12d,29d SHOW Menu2,13d,29d SHOW Mesg4,16d,29d

Input:

mov ah,2 ;选择难度 mov dh,16d mov dl,40d int 10h mov bl,7 mov ah,1 int 21h cmp al,1bh je Exit

push ax mov ah,1 int 21h cmp al,0dh pop ax

jne Error cmp al,\"1\" je eazy cmp al,\"2\" je hard jmp Error eazy:

mov ax,speed+2 mov speed,ax jmp Game_start hard:

mov ax,speed+4

第7页

打字练习程序

mov speed,ax jmp Game_start

Error: mov ah,2 mov dh,16d mov dl,29d int 10h mov ah,0ah mov al,20H mov bl,0 mov cx,2 int 10h jmp Input

Game_start:

clear_screen 00d,00d,24d,79d SHOW hotkey1,11,30 SHOW hotkey2,13,30 SHOW hotkey3,15,30 mov ah,7;向下滚屏 int 21h

clear_screen 00d,00d,24d,79d

;画墙壁

;上面用字符0ah填充 y++

;Init_game 00d,00d,0ah,dl,80d,nextsign1 ;下面,用字符0ah填充 y++

Init_game 24d,24d,0ah,dl,31d,nextsign2 ;左边用字符1ah填充 x++

Init_game 00d,24d,0ah,dh,25d,nextsign3 ;右边用字符1ah填充 x++

Init_game 00d,55d,0ah,dh,25d,nextsign4

SHOW scoremsg,10,60

mov al,hit_sum+1 mov hit_sum,al call print_score

Fall:

call Random

第8页

打字练习程序

mov dl,ah;获得随机数,保存至dl中 dl 为字母下落的y坐标 add dl,26;基数为26,使其在范围之内

mov al,let_base;把let_base 的字母传给letter mov letter,al;let_tab=letter ;mov al,let_tab+1 ;mov letter+1,al

add letter,ah;然后加上随机数值 ;add letter+1,ah

mov dh,0 again:

cmp dh,24; dh计数 je Onfloor

mov ah,2 mov bh,0

int 10h;curser mov ah,9

mov al,letter mov bl,7 mov cx,1

int 10h;print letter

delay: mov cx,0 dl1: push cx mov cx,50000 dl2: loop dl2

;dl=0ffh 表示输入,al=输入字符,否则无输入al=0 push dx mov ah,6 mov dl,0ffh int 21h pop dx

jz pass;无输入则直接下落 cmp al,letter jz to_hit

cmp al,1bh;=ESC to quit jz Menu cmp al,20h jz pause pass: pop cx

第9页

打字练习程序

inc cx

cmp cx,speed;循环speed次,所以speed越大速度越慢

jne dl1 ;若输入不正确,则继续循环,继续下落,等待击建 jmp erase;正确则清楚下落的字母

;暂停,一直循环,再次输入为空格则解除暂停 pause: push dx mov ah,6 mov dl,0ffh int 21h pop dx cmp al,20h jne pause jmp pass

;使上面一行的字符消失,其Y值增加,第二次循环的时候在下一行显示 erase: mov ah,2 int 10h mov ah,9 mov al,20h mov cx,1 mov bl,0 int 10h inc dh;y++ jmp again

;;;;到达地板之后响铃 Onfloor: call bell jmp Fall

;击中后处理 to_hit:

;用黄色高亮显示击中的字符 push bx push cx mov bh,00h

mov bl,0eh;0eh黄色 mov cx,01h mov ah,09h int 10h pop cx pop bx

;延时以能看到高亮显示

第10页

打字练习程序

call sleep call bell

mov ah,2 int 10h mov ah,9 mov al,20h mov cx,1 mov bl,0 int 10h

inc hit_sum;hit_sum++

call print_score;print score jmp Fall;重新产生字母下落

Exit:

clear_screen 00d,00d,24d,79d SHOW exitmeg,12,29 mov ah,7 int 21h MOV AH,4CH INT 21H

;;;;;;;;;;;;;;;;;functions;;;;;;;;;;;;;;;;;; print_score proc push ax push dx push cx

cmp hit_sum,10 jae two mov ah,2 mov dh,12 mov dl,63 int 10h mov ah,9 mov bl,7

mov al,hit_sum add al,\"0\" mov cx,1 int 10h jmp A

;;大于十有两位数,要区别对待 two:

mov al,hit_sum mov ah,0

第11页

打字练习程序

mov dl,10 div dl push ax mov ah,2 mov dh,12 mov dl,62

int 10h ;打印十位 mov ah,9 mov bl,7 add al,\"0\" mov cx,1 int 10h pop ax mov al,ah mov ah,2 mov dh,12 mov dl,63 int 10h mov ah,9 mov bl,7 add al,\"0\" mov cx,1

int 10h ;打印个位 A:

pop cx pop dx pop ax ret

print_score endp

;;;;;;;;;;;;;;;;;;;;;;;;;;; ;将获得的随机数存在ah中

;获得系统时间 dh=秒 dl=百分秒Random proc push cx push dx mov ah,2ch int 21h add dh,dl mov al,dh mov ah,0

mov dl,26 ;26个字母 故模26 div dl pop dx pop cx

第12页

打字练习程序

ret

Random endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;延时程序,用了三个嵌套循环 sleep proc push cx mov cx,300d lop1: push cx

mov cx, 300d lop2: push cx mov cx,300d lop3: nop nop loop lop3 pop cx loop lop2 pop cx loop lop1 pop cx ret

sleep endp

;;;;;;;;;;;;;;;;;;; ;响铃 bell proc push dx push ax push cx

mov dx,30000d ;turn on/of 30000d times in al,61h

and al,11111100b sound: xor al,2 out 61h,al

mov cx,50h ;value of wait wait1:

loop wait1 dec dx jne sound

第13页

打字练习程序

pop cx pop ax pop dx ret

bell endp

CODESEG ENDS END START

第四章 调试与操作说明

我们采用Masm for Windows运行这个程序,以下为该程序的运行界面:

首页界面:

选择界面:

第14页

打字练习程序

菜单界面:

游戏运行界面:

第15页

打字练习程序

第五章 课程设计总结与体会

通过本次课程设计,了解了一个汇编程序开发的过程,从界面设计到代码编写,都遇到了很多的问题,例如屏幕显示字符的原理,如何把数据存入内存,如何从内存中调用数据的方法。曾经都难倒我,不过通过对书本的了解,还有同学的帮助,最终解决了这些问题。

参考资料:

1. 钱晓捷《新版汇编语言程序设计》 电子工业出版社 2. 王爽《汇编语言》 清华大学出版社

3. 钱晓捷 陈涛《16/32位微机原理,汇编语言及接口技术》机械工业出版社。

第16页

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- haog.cn 版权所有 赣ICP备2024042798号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务