汇编语言程序设计之根据输入改变屏幕颜色的代码

这篇文章主要介绍了汇编语言中的根据输入改变屏幕颜色的代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

写在前面

该程序实现了“根据输入改变屏幕颜色”。其实这个程序本身没什么意思,纯粹只是将学习到的知识融合在了一起而已。程序本身过于繁琐了,写得并不是很好。以及这是我汇编实验课程的作业,如果大家有类似作业的话希望不要过度借鉴,本程序仅供参考和学习。

1.设计目的

1)体验并了解DOS界面下色彩显示;

2)了解并掌握INT10功能BIOS调用显示屏幕控制。

2.程序功能

①创建小屏;

②提示输入姓名;

③询问背景颜色并修改背景色;

④询问字体颜色并修改字体色;

⑤询问是否闪烁并修改闪烁;

⑥输出姓名及问候语。

3.源代码

 stack segment stack db 64 dup (?) stack ends data segment buff db 50,?,50 dup(?) nam0 db 'What is your name ?$' bkc0 db 'What is your background color ?$' bkc1 db '->(input RGB:0-7):$' fc0 db 'What is your font color ?$' fc1 db '->(input RGB:0-7):$' tw0 db 'Do you like twinkle ?$' tw1 db '->(like:1 dislike:0): $' hel0 db 'Hello!$' hel1 db 'Welcome to MASM!$' arro db '->$' data ends code segment assume cs:code,ds:data,ss:stack start: mov ax,data mov ds,ax    ;使ds指向data数据段 mov ah,6    ;初始化屏幕 mov al,0 mov ch,0 mov cl,0 mov dh,24 mov dl,79 mov bh,7 int 10h mov bh,00001111b  ;黑底白字 call scroll call cursor mov dx,offset nam0 mov ah,9 int 21h    ;输出字符串,提示输入姓名 mov bh,10001111b call scroll call cursor mov dx,offset buff mov ah,10 int 21h    ;输入字符串至缓冲区 call scroll mov bh,00001111b  ;闪烁黑底白字 call scroll call cursor mov dx,offset bkc0 mov ah,9 int 21h    ;输出字符串,询问背景色 call scroll call cursor mov dx,offset bkc1 mov ah,9 int 21h    ;输出字符串,提示输入格式 mov bh,10001111b call scroll call cursor mov dx,offset arro mov ah,9 int 21h    ;输出箭头 mov ah,1 int 21h    ;输入背景色 sub al,30h call scroll mov cl,4 shl al,cl mov bh,00001000b add bh,al    ;将bh的4-6位改为输入的背景色 call scroll call cursor mov dx,offset fc0 mov ah,9 int 21h    ;输出字符串,询问字体色 call scroll call cursor mov dx,offset fc1 mov ah,9 int 21h    ;输出字符串,提示输入格式 or bh,10000000b call scroll call cursor mov dx,offset arro mov ah,9 int 21h    ;输出箭头 mov ah,1 int 21h    ;输入字体色 sub al,30h call scroll add bh,al    ;将bh的0-2位改为输入的字体色 and bh,01111111b call scroll call cursor mov dx,offset tw0 mov ah,9 int 21h    ;输出字符串,询问是否闪烁 call scroll call cursor mov dx,offset tw1 mov ah,9 int 21h    ;输出字符串,提示输入格式 or bh,10000000b call scroll call cursor mov dx,offset arro mov ah,9 int 21h    ;输出箭头 mov ah,1 int 21h    ;输入闪烁 sub al,30h call scroll cmp al,1 je twin and bh,01111111b  ;若闪烁,将bh的7位改为1 jmp a twin: or bh,10000000b  ;若不闪烁,将bh的7位改为0 a:  call scroll call cursormid mov dx,offset hel0 mov ah,9 int 21h    ;输出问候 push bx call scroll call cursormid mov bl,buff+1   ;将输入的字符数存至bl add bl,2    ;将bl加2,使之指向最后一个字符的下一个字符 mov bh,0    ;将bh置零 add bx,offset buff ;将buff的偏移地址加到bx中 mov byte ptr [bx],'!' ;在字符串最后写入'!' add bx,1    ;将bx加1,使之指向下一个字符 mov byte ptr [bx],'$' ;在字符串最后写入'$' mov dx,offset buff+2 mov ah,9 int 21h    ;输出字符串(即所存姓名、'!') pop bx call scroll call cursormid mov dx,offset hel1 mov ah,9 int 21h    ;输出字符串,问候 mov ah,4ch int 21h    ;结束程序 scroll proc near push ax push bx push cx push dx mov ah,6 mov al,1 mov ch,8 mov cl,30 mov dh,16 mov dl,60 int 10h    ;下滚一行 pop dx pop cx pop bx pop ax ret scroll endp cursor proc near push ax push bx push dx mov ah,2 mov dh,16 mov dl,30    ;移动光标 mov bh,0 int 10h pop dx pop bx pop ax ret cursor endp cursormid proc near push ax push bx push dx mov ah,2 mov dh,16 mov dl,38    ;移动光标 mov bh,0 int 10h pop dx pop bx pop ax ret cursormid endp code ends end start

4.流程图

 

总结

以上就是汇编语言程序设计之根据输入改变屏幕颜色的代码的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 汇编语言