您好,欢迎访问三七文档
实验1-1——多字节数的运算⑴、两个长度为3个字节(3B)的二进制无符号数,分别存放在首地址为buf1和buf2的连续内存单元中,编程求这两者之和,并将结果放在起始地址为res的内存单元中。例如,这两个数据为888888H、456789H,则其和应为[1]345671H。源代码如下:.modelsmall.modelsmall.stack.databuf1dd888888hbuf2dd456789hresdd0h.codestart:movax,@datamovds,axmovax,wordptrbuf1;取buf1的低16位addax,wordptrbuf2;取buf2的低16位+buf1的低16位movwordptrres,ax;相加结果存入resmovax,wordptrbuf1+2;取buf1的高16位adcax,wordptrbuf2+2;取buf2的高16位+buf1的高16位+CFmovwordptrres+2,ax;相加结果存入res;输出movcx,3;置循环初值movsi,2again:movdl,byteptrres[si];依次取res的两个字节,由高到低pushcx;保护循环值cxmovcl,4shrdl,cl;将dl高四位移到低四位popcxordl,30h;将dl高四位转化为ASCIIcmpdl,39h;判断是否大于10jbenext1adddl,7;加7转化为A到E字母输出next1:movah,2int21hmovdl,byteptrres[si]anddl,0fh;将dl高四位清零ordl,30h;;将dl低四位转化为ASCIIcmpdl,39hjbenext2adddl,7next2:movah,2int21hdecsiloopagainmovax,4c00hint21hendstart运行结果截图⑵、将两数改为3B的压缩BCD码,重复以上实验过程。例如,这两个数据为888888H、456789H,则其和应为[1]345677H(表示[1]345677)。源代码如下:.modelsmall.modelsmall.stack.databuf1dd888888hbuf2dd456789hresdd0h.codestart:movax,@datamovds,axmoval,byteptrbuf1;取buf1的低8位addal,byteptrbuf2;取buf2的低8位+buf1的低8位daa;调整为十进制movbyteptrres,al;相加结果存入resmoval,byteptrbuf1+1;取buf1的中间8位adcal,byteptrbuf2+1;取buf2的中间8位+buf1的中间8位+CFdaa;调整为十进制movbyteptrres+1,al;相加结果存入resmoval,byteptrbuf1+2;取buf1的高8位adcal,byteptrbuf2+2;取buf2的高8位+buf1的高8位+CFdaa;调整为十进制movbyteptrres+2,al;相加结果存入res;输出movcx,3;置循环初值movsi,2again:movdl,byteptrres[si];依次取res的两个字节,由高到低pushcx;保护循环值cxmovcl,4shrdl,cl;将dl高四位移到低四位popcxordl,30h;将dl高四位转化为ASCIIcmpdl,39h;判断是否大于10jbenext1adddl,7;加7转化为A到E字母输出next1:movah,2int21hmovdl,byteptrres[si]anddl,0fh;将dl高四位清零ordl,30h;;将dl低四位转化为ASCIIcmpdl,39hjbenext2adddl,7next2:movah,2int21hdecsiloopagainmovax,4c00hint21hendstart运行结果截图:实验1-2——BCD码操作⑴、将存放在首地址为buf的5B的压缩BCD码分离为10B的非压缩BCD码,并存于首地址为res的单元中原代码如下:..modelsmall.stack.databufdt1223568941h;resdt?.codestart:movax,@datamovds,axmovcx,5xorsi,si;置循环次数leadi,buf;取其地址again:movdl,[di];取两个字节先保存低四位后保存高四位anddl,0fh;置高四位为零movbyteptrres[si],dl;保存到res单元movdl,[di]pushcx;保护循环次数movcl,4shrdl,cl;高四位移到第四位,并置高四位为零popcxincsimovbyteptrres[si],dlincsiincdiloopagain;循环继续取值decsi;输出,由高位开始输出movcx,10again1:movdl,byteptrres[si];依次取res的两个字节,由高到低pushcx;保护循环值cxmovcl,4shrdl,cl;将dl高四位移到低四位popcxordl,30h;将dl高四位转化为ASCIImovah,2int21hmovdl,byteptrres[si]anddl,0fh;将dl高四位清零ordl,30h;;将dl低四位转化为ASCIImovah,2int21hdecsiloopagain1movax,4c00hint21hendstart运行结果截图⑵、将存放在首地址为buf的10B的非压缩BCD码合并为5B的压缩BCD码,并存于首地址为res的单元中。10B的非压缩BCD码数据请自行设计。源代码如下:.modelsmall.stack.databufdt01020203050608090401h;resdt?.codestart:movax,@datamovds,axmovcx,5xorsi,si;置循环次数leadi,buf;取其地址again:movdl,[di];取两个字节incdimoval,[di];再依次取两个字节pushcxmovcl,4;其中高位移四位shlal,clpopcxordl,al;相与后将其前导覆盖movbyteptrres[si],dl;保存到res单元incsiincdiloopagain;循环继续取值decsi;输出,由高位开始输出movcx,5again1:movdl,byteptrres[si];依次取res的两个字节,由高到低pushcx;保护循环值cxmovcl,4shrdl,cl;将dl高四位移到低四位popcxordl,30h;将dl高四位转化为ASCIImovah,2int21hmovdl,byteptrres[si]anddl,0fh;将dl高四位清零ordl,30h;;将dl低四位转化为ASCIImovah,2int21hdecsiloopagain1movax,4c00hint21hendstart运行结果截图:⑶、将存放在内存单元buf(字节)中的BCD码转为相应的数据并存到res(字节)单元。例如将35H转换为二进制数据应得到23H、即十进制的35。源代码如下:.modelsmall.stack.databufdb35h.codestart:movax,@datamovds,axmovdl,bufmovcl,4shrdl,clmovbl,dl;bl=00000011movdl,bufanddl,0fh;dl=00000101;利用移位指令,实现数值bl乘以10shlbl,1;bl=00000110moval,blshlbl,1shlbl,1;bl=00011000addbl,al;bl=00011110;将乘于十之后的bl与dl相加addbl,dl;bl=00100011;输出movdl,blmovcl,4shrdl,clordl,30hcmpdl,39h;判断是否大于10jbenext1adddl,7;加7转化为A到E字母输出next1:movah,2int21hmovdl,blanddl,0fhordl,30hcmpdl,39hjbenext2adddl,7next2:movah,2int21hmovax,4c00hint21hendstart运行结果截图:实验1-3——数据的求和、求均源代码如下:.modelsmall.stack.databufdw0,1,2,3,4,5,6,7,8,9,90,91,92,93,94,95,96,97,98,99res1dw?res2dw?res3dw?.codestart:movax,@datamovds,axleadi,bufmovcx,14h;循环次数,即20Dxorbx,bx;运算结果保存在bx里面again:adcbx,[di]adddi,2loopagainmovres1,bx;计算的结果和保存在res1movdx,0movax,bxmovbx,0014hidivbx;计算平均数movres2,ax;所得的商保存在res2movres3,dx;所得的余数保存在res3movbx,res2movdl,bh;输出商,形式为十六进制movcl,4shrdl,clordl,30hmovah,2int21hmovdl,bhanddl,0fhordl,30hcmpdl,39hjbenext1adddl,7next1:movah,2int21hmovdl,blmovcl,4shrdl,clordl,30hcmpdl,39hjbenext2adddl,7next2:movah,2int21hmovdl,blanddl,0fhordl,30hcmpdl,39hjbenext3adddl,7next3:movah,2int21hmovah,2movdl,0ahint21hmovbx,res3movdl,bh;输出余数,形式为十六进制movcl,4shrdl,clordl,30hmovah,2int21hmovdl,bhanddl,0fhordl,30hcmpdl,39hjbenext4adddl,7next4:movah,2int21hmovdl,blmovcl,4shrdl,clordl,30hcmpdl,39hjbenext5adddl,7next5:movah,2int21hmovdl,blanddl,0fhordl,30hcmpdl,39hjbenext6adddl,7next6:movah,2int21hmovax,4c00hint21hendstart运行结果截图:实验1-4——联合移位、代码转换和字符输出⑴、将存放在首地址为buf、长度为3B的数据联合左移2位。例如,左移前为888888H,左移后应为222220H源代码如下:.modelsmall.stack.databufdf888888h.codestart:movax,@datamovds,axshlwordptrbuf,1;低四位左移一位rclwordptrbuf+2,1;高四位循环左移一位shlwordptrbuf,1;低四位左移一位rclwordptrbuf+2,1;高四位循环左移一位;输出movbx,wordptrbuf+2movdl,blanddl,0fhordl,30hmovah,2int21hmovdl,blmovcl,4shrdl,clordl,30hmovah,2int21h;以上输出高两个字节movbx,wordptrbufmovdl,bhmovcl,4shrdl,clordl,30hmovah,2int21hmovdl,bhanddl,0fhordl,30hmovah,2int21h;以上输出中间两个字节movdl,blmovcl,4shrdl,clordl,30hmovah,2int21hmovdl,blanddl,0fhordl,30hmovah,2int21h;以上输出低两个字节movax,4c00hint21hendstart运行结果截图:⑵、将存放在首地址为buf、长度为3B数据,通过调用INT21H
本文标题:汇编程序
链接地址:https://www.777doc.com/doc-4312821 .html