实验报告.docx
《实验报告.docx》由会员分享,可在线阅读,更多相关《实验报告.docx(22页珍藏版)》请在冰豆网上搜索。
![实验报告.docx](https://file1.bdocx.com/fileroot1/2023-1/27/f13fad41-e8f8-4259-8fce-a546cf2a959f/f13fad41-e8f8-4259-8fce-a546cf2a959f1.gif)
实验报告
实
验
报
告
班级:
姓名:
学号:
实验1:
题目:
—两个多位十进制数相加:
将两个多位十进制数相加,要求加数均以ASCII码形式各自顺序存放在以DATA1和DATA2为首的5个内存单元中(低位在前),结果送回DATA1处。
流程图:
程序源码:
datasegment;ByXdestiny0412090220090956
data1db6,?
6dup(30h);加数
data2db6,?
6dup(30h);被加数
dataends
stacksegmentstack
db200dup(?
)
stackends
codesegment
assumecs:
code,ss:
stack,ds:
data
begin:
movax,data
movds,ax
movah,0ah;读取加数与被加数
movdx,offsetdata1
int21h
movah,2
movdl,0dh
int21h
movdl,0ah
int21h
movah,0ah
movdx,offsetdata2
int21h
movah,2
movdl,0dh
int21h
movdl,0ah
int21h
movsi,offsetdata1
movax,[si+1]
andax,00ffh
movbx,ax
movbyteptr[bx+si+2],'0';将未用到的数字位置0
movdi,offsetdata2
movbx,[di+1]
andbx,00ffh
movbyteptr[bx+di+2],'0';将未用到的数字位置0
movcx,2
pushax
divcl
cmpal,0
jzre
andax,00ffh
movcx,ax
popax;将低位放在存储器的低地址,高位放高地址
ch1:
pushsi
pushbx
movbx,cx
movdl,[bx+si+1]
pushbx
movbx,ax
subbx,cx
movdh,[bx+si+2]
mov[bx+si+2],dl
popbx
mov[bx+si+1],dh
popbx
popsi
loopch1
re:
movcx,2
pushax
movax,bx
divcl
cmpal,0
jzren
andax,00ffh
movcx,ax
popax
ch2:
pushdi;将低位放在存储器的低地址,高位放高地址
pushax
pushbx
movax,bx
movbx,cx
movdl,[bx+di+1]
pushbx
movbx,ax
subbx,cx
movdh,[bx+di+2]
mov[bx+di+2],dl
popbx
mov[bx+di+1],dh
popbx
popax
popsi
loopch2
ren:
movsi,offsetdata1
movdi,offsetdata2
movcx,5;进行5位数的加法
pushcx
Mlen:
movbx,1
movah,0
sahf
cal:
moval,[si+1+bx];逐位进行加法运算
pushf
subal,30h
movah,[di+1+bx]
subah,30h
popf
adcal,ah
pushf
andax,00ffh
popf
aaa
mov[si+1+bx],al
cmpah,0
jzcarry;大于10则C标志位置1
stc
carry:
incbx
loopcal
popcx
jncex1
jcot1
ex1:
movbx,cx
cmpbyteptr[bx+si+1],0;没进位则除去高位的0
loopzex1
inccx
jmpot
ot1:
movdl,'1';最高位有进位则输出一个1
movah,2
int21h
ot:
movbx,cx;将得数按位输出
movdl,[si+1+bx]
ordl,30h
movah,2
int21h
loopot
movah,4ch
int21h
codeends
endbegin
程序运行结果:
实验2:
题目:
—BCD码相乘:
实现BCD码的乘法,要求被乘数和乘数(0~99)以压缩BCD码形式存放,各占1个字节内存单元。
乘积存放在另外2个字节内存单元中。
流程图:
程序源码:
datasegment;ByXdestiny0412090220090956
data1db3;被乘数
db?
db3dup(30h)
data2db3;乘数
db?
db3dup(30h)
dataends
stacksegmentstack
db200dup(?
)
stackends
codesegment
assumecs:
code,ds:
data,ss:
stack
begin:
movax,data
movds,ax
movah,0ah
movdx,offsetdata1
int21h
movbx,dx
movcl,[bx+1];CL中存放数的位数
cmpcl,1
jnzmul2;如果为1位数则高位添0
moval,[bx+2]
movbyteptr[bx+2],30h
mov[bx+3],al
mul2:
movah,2
movdl,0dh
int21h
movdl,0ah
int21h
movah,0ah
movdx,offsetdata2
int21h
movbx,dx
movcl,[bx+1];CL中存放数的位数
cmpcl,1
jnzdeal;如果为1位数则高位添0
moval,[bx+2]
movbyteptr[bx+2],30h
mov[bx+3],al
deal:
movah,2;回车换行处理
movdl,0dh
int21h
movdl,0ah
int21h
movcl,4
movsi,offsetdata1
movdi,offsetdata2
moval,[si+3]
subal,30h
movbl,[di+3]
subbl,30h
mulbl;逐位相乘
aam;处理为非压缩BCD码
shlal,cl
shrax,cl;变为压缩BCD码
movdx,ax;结果放在DX中
moval,[si+2]
subal,30h
mulbl
aam
shlal,cl
addal,dl;与前一次运算结果相加并处理为压缩BCD码
daa
movdl,al
adcdh,ah
moval,dh
daa
movdh,al
moval,[si+3]
subal,30h
movbl,[di+2]
subbl,30h
mulbl
aam
shlal,cl
addal,dl
daa
movdl,al
adcdh,ah
moval,dh
daa
movdh,al
moval,[si+2]
subal,30h
mulbl
aam
shlal,cl
shlax,cl
adddh,ah
moval,dh
daa
movdh,al
movch,0;CH=0则未开始输出数字
movcl,4
movax,dx;开始逐位输出结果
pushax
andah,0f0h
shrah,cl
movdl,ah;将每一位数放在DL
cmpdl,0;若为0则不输出
jztwo
incch
ordl,30h
movah,2
int21h
two:
popax
pushax
andah,0fh
movdl,ah
pushdx
adddl,ch
cmpdl,0
popdx
jzthree;如果未开始输出且为0则不输出
incch
ordl,30h
movah,2
int21h
three:
popax
pushax
andal,0f0h
movdl,al
shrdl,cl
pushdx
adddl,ch
cmpdl,0
popdx
jzfour;如果未开始输出且为0则不输出
ordl,30h
movah,2
int21h
four:
popax
andal,0fh
movdl,al
ordl,30h
movah,2
int21h
movah,4ch
int21h
codeends
endbegin
程序运行结果:
实验3:
题目:
—字符匹配程序:
从键盘上输入一个字符串,回车结束并回显。
用串操作指令设计程序,实现在输入的字符串存储区中寻找空格字符,退出时给出是否找到的信息,并给出具体位置。
流程图:
程序源码:
datasegment;ByXdestiny0412090220090956
data1db'findit!
',0dh,0ah,'$';发现
data2db'nooooot!
',0dh,0ah,'$';没发现
inputdb30;输入的字符串
db?
db30dup(?
)
dataends
stacksegmentstack
db200dup(?
)
stackends
extrasegment
targetdb30dup(?
);在附加段中的输入的字符串
extraends
codesegment
assumecs:
code,ds:
data,es:
extra,ss:
stack
begin:
movax,data
movds,ax
movax,extra
moves,ax
movah,0ah
movdx,offsetinput
int21h
movbx,offsetinput
movsi,[bx+1]
andsi,00ffh
movbyteptr[bx+si+2],0dh
incsi
movbyteptr[bx+si+2],0ah
incsi
movbyteptr[bx+si+2],'$';输入字符串,并加上换行回车
movah,2
movdl,0dh
int21h
movdl,0ah
int21h;屏幕上回车换行
movcx,si
movdi,0
loo1:
movdl,[bx+di+2]
int21h
incdi
looploo1;输出字符串
movdi,offsettarget
movsi,offsetinput
addsi,2
movcx,[bx+1]
andcx,00ffh
addcx,3
pushcx
repmovsb;字符串转移至附加段
popcx
moval,20h
movdi,offsettarget
movbx,di
movsi,0;辅助判断是否需要输出对应信息
loo3:
repnescasb;找空格
jcxzloo2
cmpsi,0
jzfind
con:
pushdi
subdi,bx
movdx,di
calldealnum
movah,2
movdl,20h
int21h
popdi
jmploo3
final:
movah,8;程序结束
int21h
movah,4ch
int21h
loo2:
cmpsi,0;输出没找到
jnzfinal
movdx,offsetdata2
movah,9
int21h
jmpfinal
find:
movdx,offsetdata1;输出找到
movah,9
int21h
incsi
jmpcon
dealnumproc;处理输出数字的过程
pushax
pushbx
pushcx
anddx,00ffh
movax,dx
movbx,10
divbl
pushax
movdl,al
ordl,30h
movah,2
int21h
popax
movdl,ah
movah,2
ordl,30h
int21h
popcx
popbx
popax
ret
dealnumendp
codeends
endbegin
程序运行结果:
实验4:
题目:
—冒泡法排序:
在自BLOCK开始的存储区内有10个以压缩BCD码存放的无符号数(0~99),试用冒泡法排序,并将排序结果输出显示。
流程图:
程序源码:
datasegment
blockdb12h,21h,10h,09h,56h,43h,78h,99h,00h,66h
dataends
stacksegmentstack
db200dup(?
)
stackends
codesegment
assumecs:
code,ds:
data
begin:
movax,data
movds,ax
movbx,offsetblock
movcx,10
movsi,0
loo4:
andax,0;输出排序前内存中的数列
moval,[bx+si]
pushcx
movcl,4
shlax,cl
shral,cl
popcx
movdl,ah
adddl,30h
movah,02h
pushax
int21h
popax
movdl,al
adddl,30h
int21h
movdl,20h
int21h
incsi
looploo4
movbx,offsetblock
movcx,10
loo1:
pushcx;二重循环进行冒泡排序
movsi,0
deccx
loo2:
moval,[bx+si]
movah,byteptr[bx+si+1]
cmpal,ah;比较前后两个数
jnanchg;大于则交换
mov[bx+si],ah
mov[bx+si+1],al
nchg:
incsi
cmpcx,0
jzstr
looploo2
str:
popcx
looploo1
movcx,10
movsi,0
loo3:
andax,0;输出排序后的数列
moval,[bx+si]
pushcx
movcl,4
shlax,cl
shral,cl
popcx
movdl,ah
adddl,30h
movah,02h
pushax
int21h
popax
movdl,al
adddl,30h
int21h
movdl,20h
int21h
incsi
looploo3
movah,01h
int21h
movah,4ch
int21h
codeends
endbegin
程序运行结果: