微机原理程序题_第1页
微机原理程序题_第2页
微机原理程序题_第3页
微机原理程序题_第4页
微机原理程序题_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 .将以下c语言程序的代码片段转换为功能等效的汇编语言代码片段: sign和sinteger两者都是双字变量。if (sinteger=0)sign=0;else if (第0级)sign=1;elsesign=-1;mov eax,sintegermov edx,signcmp eax,0jnz L1mov ebx,0L1:cmp ebx,0jl2mov ebx,1L2:mov ebx,-12 .将以下c语言程序的代码片段转换为功能等效的汇编语言代码片段: ch1和caps是字节变量。if (ch1=ach1=z)caps=0;if (ch1=ach1=z)caps=1;mov ax,ch1mov bx、capscmp ax,ajb nextcmp ax,zja nextmov bx,0next:cmp ax,ajl donecmp ax,zja donedone:战斗机3 .将以下c语言程序的代码片段转换为功能等效的汇编语言代码片段: 但是,sum和I变量都是全局变量。sum=0;for (i=1; i=100; I )if (i%2=0)sum=sum i;mov ecx,Imov ecx,1. while(ecx=100 )mov eax,ecxxor edx、edxmov ebx,2div ebxcmp edx,0jnz nextadd sum,ecxnext:inc ecx. endw不能被1.4整除但不能被100整除或被400整除的年是闰年。 对完整的程序进行编程,求出2012年2099年的所有闰年,并将其存储在数组Lyear中。算法说明 esi=0; ecx=2012; while (ecx2100 )if (year mod4=0andyearmod 100 ) or (year mod 400=0) then Lyearesi=ecx; esi; 以下称为ecx;以下 Lcounter=esi;include io32.inc. dataLyear dword 100 dup (? 中所述情节,对概念设计中的量体体积进行分析Lcounter dword 0. code主proc兼作xoresi、esi esi闰年数计数器、Lyear下标。movecx,2012; ecx年计数器。. while (ecx2100 )moveax,ecxxoredx、edxmovebx,400divebxcmpedx,0jzsp; if year mod 400=0 then goto leapmoveax,ecxxoredx、edxmovebx,4divebxcmpedx,0jnznext; if year mod 40 then goto nextmoveax,ecxxoredx、edxmovebx,100divebxcmpedx,0jznext; if year mod 100=0 then goto nextleap :移动年 ESI *4,ecxincesimoveax,ecxcalldispuid; 验证输出。 可以删除calldispcrlf; 验证输出。 可以删除next:incecx. endwmovLcounter,esimoveax,esicalldispuid; 验证输出。 可以删除calldispcrlf; 验证输出。 可以删除retmainendp; 最后一球end main; 最后关闭组件2 .对完整的程序进行编程,求出2100之间的所有素数,并存储到Prime数组、素数中的个数保存在变量Pcounter中。使用伪代码的算法的记述 1. i=2 to 100 do 1.1 if i is prime number then print i细分化1.1如下 1.1 j=2 to i/2 do 1.1.1 if i mod j=0 then goto next i1.1.2打印I合理地分配寄存器,将i=ebx、j=ecx、edxeax作为被除数,将ecx作为除数include io32.inc. datamsgbytytelistofprimnumber,13,10,0msg1bytelcounteris :13,10,0blankbyte,0prime dword 100 dup (? 中所述情节,对概念设计中的量体体积进行分析pcounter dword 0. code主proc; 主程序开始mov esi,0moveax,offset msgcall dispmsgmovebx,2iLoop:cmpebx,100; I循环入口jadonemovecx,ebxshrecx,1; j=i/2jLoop:cmpecx,2; j循环入口jbprintmoveax,ebxcdq; xor edx、edxdivecx; 被除数传送eax,32位除法oredx,edx; cmp edx,0jznexti; if i mod j=0 then goto next idececxjmpjLoopprint:movprimeesi*4、ebxincesimoveax,ebxmoveax,offset blankcall dispmsg; 显示空间nexti:incebx; i=i 1jmpiLoopdone:calldispcrlfmoveax,offset msg1call dispmsgmovpcounter,esimoveax,esicall dispuidcalldispcrlfret; 返回操作系统mainendp; 主程序结束end main; 最后关闭组件3 .程序写下完整的程序,倒序存储阵列aray的要素,要求附加给程序的变量最少。该段的定义如下:. data阵列向导12、4、168、122、- 33、56、78、99、345、66、-5使用伪代码的算法的记述 1. i=n-1 downto 1 do 1.1j=0 to i-1 1.1.1 if ajaj 1 then swap合理分配寄存器,i=ecx,j=edx,i-1=ecx-1include io32.inc. data; set data segmentblank 3字节3 dup (20h ),0阵列向导12,4,- 168,122,33,56,78,99,345,-66,-5char byte?msg字节13,10,press any key to continue .0; 字符串. code主procmovecx、(阵列长度)-1; 计数周期初始值iLoop: I循环入口dececx; ecx=i-1xoredx、edxjLoop: j循环入口、循环控制变量edxcmpedx,ecxjgnextimoveax,arrayedx*4cmpeax,arrayedx*4 4jgenextjxchgeax,arrayedx*4 4movarrayedx*4,eaxnextj: incedxjmpjLoopnexti: inc ecx; retrieve ecxloopiLoopprint: xorecx,ecxagain: cmpecx,阵列长度- 1jgdonemoveax,arrayecx*4calldispsidmov eax、offset blank3; 显示空间call dispmsgincecxjmpagaindone: mov eax,offset msg; 显示为:press any key to continuecall dispmsgmov eax,offset char; 暂停,等待按任意键call readcret; 返回操作系统mainendppend main; 最后关闭组件4 .编程完整的程序,求出阵列aray的最大值和最小值,分别存储到max和min元中。 该段的定义如下:. data阵列向导12,4,- 168,122,- 33,56,78,99,345,-66,-5min dword?max dword?include io32.inc. data阵列向导12,4,- 168,122,- 33,56,78,99,345,-66,-5min dword?max dword?promptbyteteentertainmenters :0maxStrbytemax=%d,13,10,0; 显示字符串的格式描述列minStrbytemin=%d,13,10,0. code主procmovecx,lengthof ara -1moveax,ara0; eax:maxmovebx、eax; ebx,minmovesi,1again:cmpeax,araesi*4jgesmallmoveax,araesi*4small:cmpebx,araesi*4jlenextmovebx,araesi*4next:incesiloopagainmovmax,eaxmovmin,ebxret; 返回操作系统mainendppend main5 .对完整的程序统计msg中的空格个数和小写字母个数进行编程,分别存储在space单元和char单元中。 该段的定义如下:. datamsg byte I love XUT!13、10、0space dword?char dword?include io32.inc. datamsg byte I love XUT!13、10、0space dw

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论