重庆it培训机构 > 汇编语言程序设计:[12]打字练习动画交互

汇编语言程序设计:[12]打字练习动画交互

简介


汇编语言(Assembly Language)是面向机器的程序设计语言。在汇编语言中,用助记符(Memoni)代替机器指令的操作码,用地址符号(Symbol)或标号(Label)代替指令或操作数的地址,如此就增强了程序的可读性并且降低了编写难度,象这样符号化的程序设计语言就是汇编语言,因此亦称为符号语言。使用汇编语言编写的程序,机器不能直接识别,还要由汇编程序或者叫汇编语言编译器转换成机器指令。汇编程序将符号化的操作代码组装成处理器可以识别的机器指令,这个组装的过程称为组合或者汇编。因此,有时候人们也把汇编语言称为组合语言。

工具/原料


Assembly Language Masm汇编编译器

方法/步骤


1打开masm汇编编译程序,新建一个masm源文件脚本。DATAS SEGMENT ;此处输入数据段代码 DATAS ENDSSTACKS SEGMENT ;此处输入堆栈段代码STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX ;此处输入代码段代码 MOV AH,4CH INT 21HCODES ENDS END START

2在正文中输入我们的程序代码,并将文件命名为testword.asmInit_game macro op1,op2,op3,op4,op5,op6 mov cx,00h mov dh,op1 mov dl,op2op6:mov ah,02h mov bh,00h int 10h push cx mov ah,0ah mov al,op3 mov bh,00h mov cx,01h int 10h pop cx inc cx inc op4 cmp cx,op5 jne op6 endmclear_screen macro op1,op2,op3,op4 ;清屏宏定义 mov ah,06h mov al,00h mov bh,07h mov ch,op1 mov cl,op2 mov dh,op3 mov dl,op4 int 10h mov ah,02h mov bh,00h mov dh,00h mov dl,00h int 10hendmmenu macro op1,op2,op3 ;菜单显示宏定义 mov ah,02h mov bh,00h mov dh,op1 mov dl,op2 int 10h mov ah,09h lea dx,op3 int 21hendmdata segment ZK db "xiaobo welcome you to play $" no db "*****Designed by 1wangxiaobo@163.com!*****",0dh,0ah," ^Henan University of Economics and Law^'date:2014/4/24$"meg db "press Enter key to continue.......$"meg1 db "when a letter is dropping,please hit it!$"meg2 db "press space key to pause!$"meg3 db "press ESC key to return main interface!$"meg4 db "press letter 'E' to exit!$"speed dw 600dletters db "jwmilzoeucgpravskntxhdyqfb" db "iytpkwnxlsvxrmofzhgaebudjq" db "nwimzoexrphysfqtvdcgljukda"letters_bak db "jwmilzoeucgpravskntxhdyqfb" db "iytpkwnxlsvxrmofzhgaebudjq" db "nwimzoexrphysfqtvdcgljukda"letter_counter db 0 life_flag db 78 dup(0)position_flag db 78 dup(0) present_position db 1 data endsstack segment para stack 'stack' db 64 dup(0)stack endscode segment main proc far assume cs:code,ds:data,ss:stack start: mov ax,data mov ds,ax mov letter_counter,00h mov present_position,1 lea si,position_flag mov ah,00h mov cx,00hinit_postion_flag: mov [si],ah inc si inc cx cmp cx,78d jne init_postion_flag lea di,letters lea si,letters_bak mov cx,00hinit_letters: mov ah,[si] mov [di],ah inc si inc di inc cx cmp cx,78d jne init_letters mov ah,00h lea si,life_flag mov cx,00hinit_life_flag: mov [si],ah inc si inc cx cmp cx,78d jne init_life_flag mov cx,00h mov ah,01h or ch,00010000b int 10hclear_screen 00d,00d,24d,79d Init_game 00d,00d,0ah,dl,80d,nextsign1 Init_game 24d,00d,0ah,dl,80d,nextsign2 Init_game 00d,00d,0ah,dh,25d,nextsign3 Init_game 00d,79d,0ah,dh,25d,nextsign4 menu 05d,15d,ZK ;菜单信息的宏调用 menu 07h,15d,no menu 09d,15d,meg menu 11d,15d,meg1 menu 13d,15d,meg2 menu 15d,15d,meg3 menu 17d,15d,meg4 put: mov ah,02h ;设置光标位置 mov bh,00h mov dh,22d mov dl,33d int 10h mov ah,01h ;从键盘输入任意字符 int 21h cmp al,0dh je speed3 cmp al,45h je exitexit: mov ah,4ch int 21h speed3: mov ax,speed+12 mov speed,ax jmp begin begin: clear_screen 01d,01d,23d,78d ;清屏宏调用 clear_screen 01d,01d,23d,78d Init_game 23d,01d,01h,dl,78d,nextsign5 mov ah,02h mov bh,00h mov dh,01h mov dl,01h int 10h mov cx,00h lea si,lettersnextletter: mov ah,02h ;显示字母 mov dl,[si] int 21h inc si inc cx cmp cx,78d je nextcycle jmp nextletterfrom_front: sub present_position,78d jmp gobackto_sifind_zero: cmp letter_counter,78d je recycle cmp present_position,78d je from_one mov ah,00hnextsi: add present_position,01h inc si cmp [si],ah je gobackto_di cmp present_position,78d je from_one jmp nextsifrom_one:mov present_position,01h jmp gobackto_sirecycle:mov letter_counter,00h mov present_position,01d lea si,position_flag mov cx,00h mov ah,00hclearsi: mov [si],ah inc cx cmp cx,78d je nextcycle inc si jmp clearsinextcycle: lea di,letters lea si,position_flag add present_position,31d cmp present_position,78 ja from_frontgobackto_si: add si,word ptr present_position dec si mov ah,[si] cmp ah,01h je find_zerogobackto_di: mov ah,01h mov [si],ah add di,word ptr present_position dec di mov dl,present_position mov ah,02h mov bh,00h mov dh,01h int 10h mov cx,00hnextrow: push cx mov cx,00hout_cycle: ; 延迟 push cx mov cx,00hin_cycle: add cx,01h cmp cx,1000 jne in_cycle push dx mov ah,06h ;从键盘输入字符 mov dl,0ffh int 21h pop dx jz pass cmp al,1bh ;如果键入ESC,则返回主菜单 je to_start1 cmp al," " ;如果键入SPACE,则游戏暂停 je pause cmp al,[di] ;输入字母正确!则字母消失 je disappearpass: pop cx inc cx cmp cx,speed je print jmp out_cyclepause: push dx ;暂停处理 mov ah,06h mov dl,0ffh int 21h pop dx cmp al," " jne pause jmp passto_start1: ;返回主菜单 jmp startprint: mov ah,0ah ;在当前光标位置写空格 mov al," " mov bh,00h mov cx,01h int 10h inc dh mov ah,02h ;改变光标位置 mov bh,00h int 10h mov ah,0ah ;在当前光标位置写字母 mov al,[di] mov bh,00h mov cx,01h int 10h pop cx inc cx cmp cx,21d je print_next_letter jmp nextrow ;下一行disappear: ;击中字母后输出空格 pop cx pop cx mov ah,0ah mov al," " mov bh,00h mov cx,01h int 10h jmp hit print_next_letter: lea si,life_flag add si,word ptr present_position dec si mov ah,0ah mov al," " mov bh,00h mov cx,01h int 10h inc dh mov ah,02h mov bh,00h int 10h mov ah,0ah mov al," " mov bh,00h mov cx,01h int 10h mov ah,1 mov [si],ah hit: mov ah,02h mov bh,00h mov dh,01h mov dl,present_position int 10h mov al,[di] ; 出现下一个新字母的数法 add al,7 cmp al,7ah ja convey_letter mov ah,0ah mov bh,00h mov cx,01h int 10h mov [di],al add letter_counter,01h jmp nextcycle convey_letter: sub al,7ah add al,61h mov ah,0ah mov bh,00h mov cx,01h int 10h mov [di],al add letter_counter,01h jmp nextcycle clear_screen 01,01,23,78 mov ah,02h mov bh,00h mov dh,11d mov dl,20d int 10h inc dh inc dh mov ah,02h mov bh,00h int 10hnotkey: mov ah,07h int 21h cmp al,0dh je to_start cmp al,1bh je over jmp notkeyto_start: clear_screen 00,00,24,79 jmp startover: clear_screen 01,01,23,78 mov ah,02h mov bh,00h mov dh,11d mov dl,15h int 10h mov ah,02h mov bh,00h mov dh,13d mov dl,15h int 10h mov ah,07h int 21h mov ah,07h int 21h clear_screen 00,00,24,79 mov ax,4c00h int 21hmain endpcode endsend start

3运行我们编辑的文件◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙ xiaobo welcome you to play ◙ *****Designed by 1wangxiaobo@163.com!***** ^Henan University of Economics and Law^'date:2014/4/24 press Enter key to continue....... ◙ when a letter is dropping,please hit it! ◙ press space key to pause! ◙ press ESC key to return main interface! ◙ press letter 'E' to exit! ◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙运行可执行程序testword.exe,出现菜单主界面,按回车键出现由26个字母组成的乱序行,这时其中任一字母落下,在键盘上敲入该字母,如果输入正确,字母消失;按ESC键返回主界面;按空格见暂停;按‘E’退出。

点击显示全文

加载中...
加载中...
今日热点信息
精彩推荐
手机版 | 欢迎来到重庆it培训机构
RSS订阅