我是靠谱客的博主 紧张黑猫,这篇文章主要介绍汇编语言程序设计之根据输入改变屏幕颜色的代码,现在分享给大家,希望可以做个参考。

写在前面

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

1.设计目的

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

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

2.程序功能

①创建小屏;

②提示输入姓名;

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

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

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

⑥输出姓名及问候语。

3.源代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
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.流程图

 

总结

到此这篇关于汇编语言中的根据输入改变屏幕颜色的代码的文章就介绍到这了,更多相关汇编语言改变屏幕颜色内容请搜索靠谱客以前的文章或继续浏览下面的相关文章希望大家以后多多支持靠谱客!

最后

以上就是紧张黑猫最近收集整理的关于汇编语言程序设计之根据输入改变屏幕颜色的代码的全部内容,更多相关汇编语言程序设计之根据输入改变屏幕颜色内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(142)

评论列表共有 0 条评论

立即
投稿
返回
顶部