汇编语言(实现对数据的最大最小平均值计算)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验报告课程名称微机原理与汇编语言学院计算机工程学院班级11计3Z学号11141320姓名王祖陆2013年05月27日设计一个汇编语言程序,具体内容如下:一、功能:(1)从键盘输入N个带符号数(N的值也从键盘输入,N=65535);带符号数为16位二进制数范围);(2)找出这N个数中的最大值和最小值,并且显示出来;(3)计算这N个数的平均值,并且显示出来。二、程序分析:(1)需要对程序进行N的值的输入,来确定循环的次数,决定了循环的次数就可以确定数组元素的个数,为下一步数组元素的值的输入做准备。(2)由(1)中确定N的值来决定循环的次数,每一次的循环,指针向后移两位,因为我们定义的时候是字大小,占用2个字节的空间,每一次的循环调用一次输入函数,以确定数组中每个元素的值。(3)调用清屏语句将屏幕上的输入的痕迹清除,同时用循环调用输出函数,将用户之前输入的值按一定的格式输出到屏幕上。(4)判断最大数最小数,用循环遍历数组中的每一个元素,同时与最大数最小数进行比较,如果该数比最大数大,则将其保存到最大数中,如果该数比最小数小,则将其保存到最小数中。(注:最大数和最小数需要开辟内存空间来保存,同时在进入循环之前应该给其一个值,这里我给的是数组中第一个元素的值)(5)计算平均数,同样用循环将其累加的和除以N的值即得到最终的结果三、程序相关说明:(1)程序中,COUNT保存的是循环的次数,即数组的个数N(2)ARRAY为定义的数组,MAXAY,MINAY分别对应的是最大数,最小数,WTEMP为临时变量(3)MESS系列保存的内容为输入输出时的提示信息无实际作用(4)INPUT子函数为输入N的值,READ函数为输入一个-32768~+32767的数,WRITE为输出函数,即将数组中某一元素的值输出,IFMAX函数为判断最小值最大值函数,MEAN函数为求平均值函数(5)DPCRLF、NDPCRLF子函数为输出格式控制函数四、程序流程图STARTCALLINPUTCALLREAD[BX]=AXBX-=2CALLDPCRLFCX-=1CX!=0YAX=[BX]WTEMP=AXCALLWRITEBX+=2CALLDPCRLFCX!=0YNNCALLIFMAXAX=MAXAYWTEMP=AXCALLWRITEAX=MINAYWTEMP=AXCALLWRITEAX=COUNTPUSHAXAX=ARRAYPUSHAXCALLMEANSP+=4WTEMP=AXCALLWRITEENDINPUTPUSHAXCALLREADCOUNT=AXCALLDPCRLFPOPAXRET主程序流程图INPUT函数流程图READPUSHBXPUSHCXPUSHDXXORBX,BXXORCX,CXAL==+AL==-NCX=-1AH=1INT21HYYAl0&&AL9NAL-=30HSHLBX,1DX=BXSHLBX,1SHLBX,1BX+=DXAH=0HBX+=AXYCX==0NNEGBXAX=BXPOPDXPOPCXPOPBXYNRETWRITEPUSHAXPUSHBXPUSHDXAX==0DL=’0’AH=2INT21HYNAX0YBX=AXDL=’-’AH=2HINT21HAX=BXNEGAXBX=10PUSHBXNAX==0DX=0BX.AX/=10DL+=30HPUSHDXPOPDXYNDL==10AH=2INT21NPOPDXPOPBXPOPAXYRETREAD函数流程图WRITE函数流程图IFMAXPUSHSIPUSHBXSI=AXCX-=1AX=[SI]BX=AXSI+=2AX[SI]AX=[SI]NBX[SI]BX=[SI]NYCX=0YMAXAY=AXMINAY=BXPOPBXPOPSIRETNMEANPUSHBPBP=SPPUSHBXPUSHCXPUSHDXPUSHSIPUSHDIBX=[BP+4]CX=[BP+6]SI=0DI=SIAX=[BX]CWDSI+=AXDI+=DXBX+=2CX-=1CX!=0YAX=SIDX=DICX=[BP+6]AX/=CXPOPDIPOPSIPOPDXPOPCXPOPBXPOPBPNRETIFMAX函数流程图MEAN函数流程图五、源程序列表文件内容:Microsoft(R)MacroAssemblerVersion5.005/27/1318:44:33Page1-10000DSEGSEGMENT;数据段0000506C6561736520MESS1DB'PleaseinputNN=65535:','$'696E707574204E20224E3C3D3635353335223A24001B506C6561736520MESS2DB'Pleaseinputanumber:','$'696E7075742061206E756D6265723A240032596F757220696EMESS3DB'Yourinputisasfollows:',0AH,0DH,'$'70757420697320617320666F6C6C6F77733A0A0D24004E0A0D4D41583A24MESS4DB0AH,0DH,'MAX:','$'00550A0D4D494E3A24MESS5DB0AH,0DH,'MIN:','$'005C0A0D4156455241MESS6DB0AH,0DH,'AVERAGE:','$',0AH,0DH47453A240A0D006903E8[ARRAYDW1000DUP(0)0000]0839????COUNTDW?083B????WTEMPDW?083D????MAXAYDW?083F????MINAYDW?0841DSEGENDS0000SSEGSEGMENTSTACK;堆栈段00000080[DB80HDUP(0)00]0080SSEGENDS0000CSEGSEGMENT;代码段ASSUMEDS:DSEG,SS:SSEG,CS:CSEG0000B8----RSTART:MOVAX,DSEG00038ED8MOVDS,AX0005BA0000RMOVDX,OFFSETMESS10008B409MOVAH,09H000ACD21INT21H000CE8009FRCALLINPUT;调用INPUT函数000F8B0E0839RMOVCX,COUNT0013BB0069RMOVBX,OFFSETARRAY0016BA001BRAGAIN1:MOVDX,OFFSETMESS20019B409MOVAH,9H001BCD21INT21H001DE800ABRCALLREAD;调用READ函数00208907MOV[BX],AXMicrosoft(R)MacroAssemblerVersion5.005/27/1318:44:33Page1-2002283C302ADDBX,20025E80185RCALLDPCRLF;循环COUNT次0028E2ECLOOPAGAIN1002AB003MOVAL,3H002CCD10INT10H002E8B0E0839RMOVCX,COUNT0032BB0069RMOVBX,OFFSETARRAY0035BA0032RMOVDX,OFFSETMESS30038B409MOVAH,9H003ACD21INT21H003C8B07AGAIN2:MOVAX,[BX]003EA3083BRMOVWTEMP,AX0041E800ECRCALLWRITE;调用WRITE函数004483C302ADDBX,20047E80196RCALLNDPCRLF;调用NDPCRLE函数004AE2F0LOOPAGAIN2;执行COUNT次循环004CB402MOVAH,2004EB20DMOVDL,0DH0050CD21INT21H0052B20AMOVDL,0AH0054CD21INT21H00568B0E0839RMOVCX,COUNT005AB80069RMOVAX,OFFSETARRAY005DE80130RCALLIFMAX;调用IFMAX函数0060BA004ERMOVDX,OFFSETMESS40063B409MOVAH,09H0065CD21INT21H0067A1083DRMOVAX,MAXAY006AA3083BRMOVWTEMP,AX006DE800ECRCALLWRITE;调用WRITE函数输出MAXAY0070BA0055RMOVDX,OFFSETMESS50073B409MOVAH,09H0075CD21INT21H0077A1083FRMOVAX,MINAY007AA3083BRMOVWTEMP,AX007DE800ECRCALLWRITE;调用WRITE函数输出MINAY0080BA005CRMOVDX,OFFSETMESS60083B409MOVAH,09H0085CD21INT21H0087A10839RMOVAX,COUNT008A50PUSHAX008BB80069RMOVAX,OFFSETARRAY008E50PUSHAX008FE80157RCALLMEAN009283C404ADDSP,40095A3083BRMOVWTEMP,AX0098E800ECRCALLWRITE;调用WRITE函数输出平均值Microsoft(R)MacroAssemblerVersion5.005/27/1318:44:33Page1-3009BB44CMOVAH,4CH009DCD21INT21H009FINPUTPROC009F50PUSHAX00A0E800ABRCALLREAD00A3A30839RMOVCOUNT,AX00A6E80185RCALLDPCRLF00A958POPAX00AAC3RET00ABINPUTENDP00ABREADPROC00AB53PUSHBX00AC51PUSHCX00AD52PUSHDX00AE33DBXORBX,BX;寄存器BX,CX清零00B033C9XORCX,CX00B2B401MOVAH,1H00B4CD21INT21H00B63C2BCMPAL,'+';是“+”,继续输入字符00B87407JZREAD100BA3C2DCMPAL,'-';是“-”,设置-1标志00BC7507JNZREAD200BEB9FFFFMOVCX,-100C1B401READ1:MOVAH,1H;继续输入字符00C3CD21INT21H00C53C30READ2:CMPAL,'0';不是0-9之间的字符,则输入结束00C77216JBREAD300C93C39CMPAL,'9'00CB7712JAREAD300CD2C30SUBAL,30H;是0-9之间的字符,则转换为二进制数,利用移位指令,实现数值乘1000CFD1E3SHLBX,100D18BD3MOVDX,BX00D3D1E3SHLBX,100D5D1E3SHLBX,100D703DAADDBX,DX00D9B400MOVAH,0H00DB03D8ADDBX,AX;已输入数值乘10后,与新输入数值相加00DDEBE2JMPREAD100DF83F900READ3:CMPCX,000E27402JZREAD400E4F7DBNEGBX;是负数,进行求补00E68BC3READ4:MOVAX,BX00E85APOPDX00E959POPCX00EA5BPOPBX00EBC3RET00ECREADENDP00ECWRITEPROC00EC50PUSHAXMicrosoft(R)MacroAssemblerVersion5.005/27/1318:44:33Page1-400ED53PUSHBX00EE52PUSHDX00EFA1083BRMOVAX,WTEMP;列出显示数据00F285C0TESTAX,AX;判断数据是零、正数或负数00F47509JNZWRITE100F6B230MOVDL,'0';是零,显示‘0’后退出00F8B402MOVAH,2

1 / 18
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功