王爽汇编程序设计项目.docx
《王爽汇编程序设计项目.docx》由会员分享,可在线阅读,更多相关《王爽汇编程序设计项目.docx(23页珍藏版)》请在冰豆网上搜索。
![王爽汇编程序设计项目.docx](https://file1.bdocx.com/fileroot1/2023-5/24/d8aeefdb-521d-4153-94ac-2024234a61e5/d8aeefdb-521d-4153-94ac-2024234a61e51.gif)
王爽汇编程序设计项目
王爽汇编程序设计项目
(拿到题目,建议先自己动手去做,去思考)
程序设计项目一
datasegment
dw?
dataends
end
要求:
只在定义的数据段'?
'中加入相关的内容,使得上面的程序可以在屏幕中间显示一个绿色的字符'A'。
汇编源程序设计如下:
assumecs:
data
datasegment
dw61h
start:
movax,data
movds,ax
movbx,0
movax,0b800h
moves,ax
movcx,0
movcl,ds:
[bx]
movch,00000010b
moves:
[2000],cx
movax,4c00h
int21h
dataends
endstart
通过此程序设计学习到了:
一个有意义、完整的汇编源程序必须有至少有一个代码段。
程序设计项目二
对加密的字符串进行解密。
要求:
(1)加密的字符串放在Cryptography段。
(2)解密方法:
将Cryptography段的每个字符的ASCII值减去1。
(3)用汇编语言实现程序,将Cryptography段的数据按照解密方法进行解密,将解密后的数据放在PlainText段,然后再把解密之后的字符串以白底蓝字方式显示到屏幕中间。
(4)密文和明文的数据段定义如下:
Cryptographysegment
db'tqsfbe!
zpvs!
xjoht'
db'!
!
cf!
zpvs!
nbtufs!
'
Cryptographyends
PlainTextsegment
db2*17dup('')
PlainTextends
汇编源程序设计如下:
assumeds:
cryptography,cs:
code
cryptographysegment
db'tqsfbe!
zpvs!
xjoht'
db'!
!
cf!
zpvs!
nbtufs!
'
cryptographyends
plainTextsegment
db34dup('0')
plainTextends
codesegment
start:
movax,cryptography
movds,ax
movbx,0
movdi,34
movax,0b800h
moves,ax
movcx,0
moval,0
movcx,34
s:
moval,ds:
[bx]
decal
movds:
[di],al
incbx
incdi
loops
movdi,34
movbx,46//列
movsi,1920//行
movcx,34
s1:
movah,01110001b
moval,ds:
[di]
incdi
moves:
[si+bx],ax
incsi
incsi
loops1
movax,4c00h
int21h
codeends
endstart
通过此程序设计学习到了:
定位显示时,列不能取奇数
程序设计项目三
加、减、除三则运算。
要求:
(1)读取字符串的内容,判断第四个字符是'+'、'-'或'/',然后按照相应的符号进行运算,并把运算结果转换为字符串存放在等号后面,最后把算式显示到屏幕中间,白底蓝字。
(2)注意数字字符的ASCII与数字的对应关系,数字的数值加30H为这个数字的字符所对应的ASCII。
(3)数据段定义如下:
Calculatesegment
db'1.3/1='
db'2.5+3='
db'3.9-3='
db'4.4+5='
Calculateends
汇编源程序设计如下:
assumeds:
calculate,cs:
code
calculatesegment
db'1.3/1='
db'2.5+3='
db'3.9-3='
db'4.4+5='
calculateends
stacksegment
dw64dup(0)
stackends
codesegment
start:
movax,calculate
movds,ax
movdi,3
movax,stack
movss,ax
movsp,128
movax,0b800h
moves,ax
movsi,0
movbx,1504
movcx,4
s:
pushcx
movah,0
moval,ds:
[di]
calljian0
incdi
movch,0
movcl,ds:
[di]
pushcx
movdl,cl
callchufapanduan
movcl,dl
jcxzchufa
k1:
popcx
pushcx
movdl,cl
calljianfapanduan
movcl,dl
jcxzjianfa
k3:
popcx
pushcx
movdl,cl
calljiafapanduan
movcl,dl
jcxzjiafa
k2:
popcx
popcx
adddi,12
loops
movcx,0
movcx,4
g2:
pushcx
movcx,16
g1:
movah,01110001b
moval,ds:
[si]
incsi
moves:
[bx],ax
incbx
incbx
loopg1
addbx,128
popcx
loopg2
movax,4c00h
int21h
chufa:
pushax
incdi
movch,0
movcl,ds:
[di]
moval,cl
calljian0
movcl,al
popax
divcl
incdi
incdi
addal,30h
movds:
[di],al
jmpshortk1
jiafa:
pushax
incdi
movch,0
movcl,ds:
[di]
moval,cl
calljian0
movcl,al
popax
addal,cl
addal,30h
incdi
incdi
movds:
[di],al
jmpshortk2
jianfa:
pushax
incdi
movch,0
movcl,ds:
[di]
moval,cl
calljian0
movcl,al
popax
s5:
decal
loops5
addal,30h
incdi
incdi
movds:
[di],al
jmpshortk3
jian0:
movcx,30h
s1:
decal
loops1
ret
chufapanduan:
movcx,2fh
s2:
decdl
loops2
ret
jianfapanduan:
movcx,2dh
s3:
decdl
loops3
ret
jiafapanduan:
movcx,2bh
s4:
decdl
loops4
ret
codeends
endstart
学会了:
分别设计了三个子程序分别用于除法、减法、加法的判断
通过哪种判断就执行哪种计算方法
从data段的段地址di=3开始扫描
下一行是3+16、3+16+16以此下去
结果保存等式=后面
最后显示在屏幕中间
程序设计项目四
编程计算x(x>2)的y(y>2)次方。
使用add指令实现。
另,若学到第10章,使用两种方式实现:
(1)只使用add指令实现;
(2)只使用mul指令实现;
并将计算式显示在屏幕中央。
例如:
计算4的3次方。
在屏幕中央显示格式如下:
4
^
3
-----
64
注意:
结果不能超过16位寄存器可存储的最大值。
汇编源程序设计如下:
1、只使用add指令实现
assumecs:
code
codesegment
start:
movax,0b800h
moves,ax
movsi,1504
movax,2
movdx,3
pushdx
pushax
movdi,ax
decdx
movcx,dx
movdx,ax
s1:
pushcx
movbx,ax
decax
movcx,ax
incax
movax,dx
movbx,dx
s2:
addax,bx
loops2
popcx
movdx,ax
movax,di
loops1
movax,dx
movcx,ax
popax
popdx
addax,30h
movah,00000001b
adddx,30h
movdh,00000001b
moves:
[si],ax
addsi,160
movbh,00000001b
movbl,5eh
movwordptres:
[si],bx
addsi,160
moves:
[si],dx
addsi,158
movbh,00000001b
movbl,2dh
movwordptres:
[si],bx
addsi,2
movwordptres:
[si],bx
addsi,2
movwordptres:
[si],bx
addsi,2
movwordptres:
[si],bx
addsi,156
movdi,0
movax,cx
movbx,10
h:
movdx,0
divbx
pushdx
incdi
movcx,ax
jcxzok1
jmpshorth
ok1:
movcx,di
h1:
popdx
adddx,30h
movdh,00000001b
moves:
[si],dx
addsi,2
looph1
movax,4c00h
int21h
codeends
endstart
会做项目三的基础上完成此程序并不难
程序设计项目五
定义一个数据段如下:
datasegment
db'h12E332l@L#O*&^!
88nI@cE$%%$T1Om33E44E55ty77O88u!
()'
db'?
'
dataends
注意:
第一行字符串为待处理的数据,'?
'为字符串结束符号。
设计程序完成如下操作:
(1)去掉除字母、空格、'!
'之外的字符;
(2)通过内存间的数据交换,将数据段中的字符串修改为'Hello!
Nicetomeetyou!
';
(3)在屏幕正中打印处理好后的数据。
完成程序后思考:
(1)如何设计程序,程序代码量最少;
(2)如何设计程序,程序执行速度最快;
(3)如何设计程序,使得程序具有通用性。
注意:
(1)'?
'、'!
'和空格分别假定为字符串的结束符、一句话的最后的标点和单词间的间隔符,都不属于干扰符号。
(2)这里的通用性是指:
任意带有其他符号干扰的一组字符串都能够通过程序被处理为具有如下特点的英文段落:
段落中只包含字母、空格、'!
'三种符号。
段落中的每句话都是以开头字母为大写,'!
'为结束标点的句子。
汇编源程序设计如下:
assumecs:
code
datasegment
db'h12E3321@L#o*&^!
88nI@cE$T1om33E44E55ty77o88u!
()'
db'?
'
dataends
stacksegment
dw64dup(0)
stackends
codesegment
start:
movax,data
movds,ax
movsi,0
movax,0b800h
moves,ax
movdi,1440
movah,0
movbh,0
s:
moval,ds:
[si]
incsi
movah,0
movdl,al
callzifu
jcxzxianshizifu
zf:
movah,0
moval,dl
callgan
jcxzxianshigan
gg:
movah,0
moval,dl
callkongge
jcxzxianshikong
kk:
movah,0
moval,dl
callwenhao
jcxzj
jmpshorts
xianshizifu:
moval,dl
movch,0
addbh,1
decbh
decbh
movcl,bh
jcxzdaxie
oral,00100000b
hh1:
movah,00000001b
moves:
[di],ax
adddi,2
jmpshortzf
daxie:
movch,0
movcl,20h
da:
decal
loopda
movbh,1
jmpshorthh1
xianshigan:
moval,dl
movah,00000001b
moves:
[di],ax
adddi,2
movbh,0
jmpshortgg
xianshikong:
moval,dl
movah,00000001b
moves:
[di],ax
adddi,2
jmpshortkk
j:
movax,4c00h
int21h
zifu:
oral,00100000b
movch,0
movcl,60h
z1:
decal
loopz1
movcl,26
z2:
movbl,cl
decal
movcl,al
jcxzz3
movcl,bl
loopz2
jmpshortz4
z3:
addbh,1
z4:
movcl,al
ret
gan:
movch,0
movcl,21h
g1:
decal
loopg1
movcl,al
ret
kongge:
movch,0
movcl,20h
kong1:
decal
loopkong1
movcl,al
ret
wenhao:
movch,0
movcl,3fh
w1:
decal
loopw1
movcl,al
ret
codeends
endstart
此程序也是建立在项目三的基础上的,分别建四个子程序判断字符、
空格、感叹号、问号。
难点是:
如何使每一句子开头的字母大写,句子与感叹号‘!
’为结尾
问号‘?
’结束
程序设计项目六
在屏幕中间显示:
“中华”两个字。
参看demo0.png示例。
提示:
通过字模提取工具,可以提取字的显示信息。
assumeds:
data,cs:
code
datasegment
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
db1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1
db1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1
db1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1
db1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1
db1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db0,0,0,0,0,0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0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dataends
stacksegment
dw64dup(0)
stackends
codesegment
start:
movax,0b800h
moves,ax
movdl,160
moval,16
muldl
movdi,ax
adddi,20
movax,stack
movss,ax
movsp,64
movax,data
movds,ax
movsi,0
callqingp
movbh,16
movbl,25
callzhong
movdi,0
movdl,160
moval,16
muldl
movdi,ax
adddi,80
movbh,16
movbl,30
callhua
jmpshortok
zhong:
movch,0
movcl,bh
s2:
pushcx
movch,0
movcl,bl
s1:
pushcx
movch,0
movcl,ds:
[si]
incsi
jcxzbuxianshi
movax,0403h
moves:
[di],ax
adddi,2
fh:
popcx
loops1
adddi,110
popcx
loops2
ret
buxianshi:
movax,0000h
moves:
[di],ax
adddi,2
jmpshortfh
hua:
movch,0
movcl,bh
s3:
pushcx
movch,0
movcl,bl
s4:
pushcx
movch,0
movcl,ds:
[si]
incsi
jcxzbuxianshi1
movax,0403h
moves:
[di],ax
adddi,2
fh1:
popcx
loops4
adddi,100
popcx
loops3
ret
buxianshi1:
movax,0000h
moves:
[di],ax
adddi,2
jmpshortfh1
qingp:
pushcx
pushdi
movdi,0
movcx,9000
movax,0000h
k1:
moves:
[di],ax
adddi,2
loopk1
popdi
popcx
ret
ok:
movax,4c00h
int21h
codeends
endstart
(完)