汇编语言程序设计之根据输入改变屏幕颜色的代码
<p><span style="color: #ff0000"><strong>写在前面</strong></span></p><p>该程序实现了“根据输入改变屏幕颜色”。其实这个程序本身没什么意思,纯粹只是将学习到的知识融合在了一起而已。程序本身过于繁琐了,写得并不是很好。以及这是我汇编实验课程的作业,如果大家有类似作业的话希望不要过度借鉴,本程序仅供参考和学习。</p>
<p><span style="color: #ff0000"><strong>1.设计目的</strong></span></p>
<p>1)体验并了解DOS界面下色彩显示;</p>
<p>2)了解并掌握INT10功能BIOS调用显示屏幕控制。</p>
<p><span style="color: #ff0000"><strong>2.程序功能</strong></span></p>
<p>①创建小屏;</p>
<p>②提示输入姓名;</p>
<p>③询问背景颜色并修改背景色;</p>
<p>④询问字体颜色并修改字体色;</p>
<p>⑤询问是否闪烁并修改闪烁;</p>
<p>⑥输出姓名及问候语。</p>
<p><span style="color: #ff0000"><strong>3.源代码</strong></span></p>
<div class="jb51code">
<pre class="brush:plain;">
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 ,'!' ;在字符串最后写入'!'
add bx,1 ;将bx加1,使之指向下一个字符
mov byte ptr ,'$' ;在字符串最后写入'$'
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</pre>
</div>
<p>4.流程图</p>
<p style="text-align: center"><img src="https://img.jbzj.com/file_images/article/202003/2020031213285229.png" alt="" /> </p>
<p><span style="color: #ff0000"><strong>总结</strong></span></p>
<p>到此这篇关于汇编语言中的根据输入改变屏幕颜色的代码的文章就介绍到这了,更多相关汇编语言改变屏幕颜色内容请搜索琼殿技术社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持琼殿技术社区!</p>
<div class="art_xg">
<b>您可能感兴趣的文章:</b><ul><li>汇编语言有关在屏幕区显示字符的四种方法(推荐)</li></ul>
</div>
</div>
<!--endmain-->
頁:
[1]