c语言与微机原理试题,微机原理程序题

《微机原理程序题》由会员分享,可在线阅读,更多相关《微机原理程序题(17页珍藏版)》请在人人文库网上搜索。

1、1. 将下面C语言程序的代码片段转换为功能等价的汇编语言代码片段,其中sign与sinteger均为双字变量。if ( sinteger = = 0)sign = = 0;else If ( siteger 0)sign = 1;elsesign = 1;mov eax,sintegermov edx,signcmp eax,0jnz L1mov ebx,0L1:cmp ebx,0jl L2mov ebx,1L2:mov ebx,-12. 将下面C语言程序的代码片段转换为功能等价的汇编语言代码片段,其中ch1与caps均为字节变量。if (ch1 =a & ch1 =A & ch10) or 。

2、(year mod 400=0) then; Lyearesi=ecx;esi+; ecx+; ; Lcounter=esi;include io32.inc.dataLyear dword 100 dup(?)Lcounter dword 0.codemainproc xoresi,esi ;esi闰年个数计数器,兼做Lyear下标。movecx,2012 ;ecx年份计数器。.while (ecx0 then goto nextmoveax,ecxxoredx,edxmovebx,100divebxcmpedx,0jznext;if year mod 100=0 then goto nex。

3、tleap: movLyearesi*4,ecxincesimoveax,ecxcalldispuid;输出,用于验证。可以删掉calldispcrlf ;输出,用于验证。可以删掉next:incecx.endwmovLcounter,esimoveax,esicalldispuid ;输出,用于验证。可以删掉calldispcrlf ;输出,用于验证。可以删掉retmainendp ;end of mainend main ;end of assembly2. 编程写一个完整的程序,求出2100之间的所有素数,并将它们存入Prime数组中,素数的个数存入变量Pcounter中。; 采用伪代码。

4、pseudo code描述算法; 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 i; 1.1.2 print i; 合理分配寄存器,i=ebx,j=ecx,edxeax做被除数,ecx做除数.include io32.inc.datamsgbyte List of prime number,13,10,0msg1 byte Lcounter is : ,13,10,0blankbyte ,0prim。

5、e dword 100 dup(?)pcounter dword 0.codemainproc ;主程序开始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 idececxjmpjLoopp。

6、rint:movprimeesi*4,ebxincesimoveax,ebxmoveax,offset blankcall dispmsg;显示空格nexti:incebx;i=i+1jmpiLoopdone:calldispcrlfmoveax,offset msg1call dispmsgmovpcounter,esimoveax,esicall dispuidcalldispcrlfret;返回操作系统mainendp ;主程序结束end main ;end of assembly3. 编程写一个完整的程序,将数组aray中的元素按逆序存放,要求程序中附加的变量最少。数据段的定义如下:.。

7、dataaray dword 12,4, 168,122,33,56,78,99,345, 66,5; 采用伪代码pseudo code描述算法; 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-1 include io32.inc.data ;set data segmentblank3byte 3 dup(20h),0arraydword12,4,-168,122,33,56,78,99,345,-66,-5char byte ?msg byte 13,。

8、10,press any key to continue .,0;字符串.codemainprocmovecx,(lengthof array)-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 ecxloopiLoopprin。

9、t: xorecx,ecx again: cmpecx,lengthof array-1jgdonemoveax,arrayecx*4calldispsidmov eax,offset blank3;显示空格 call dispmsgincecxjmpagaindone: mov eax,offset msg;显示:press any key to continuecall dispmsgmov eax,offset char ;暂停,等待按任意键call readcret ;返回操作系统mainendpend main ;end of assembly4. 编程写一个完整的程序,求数组ara。

10、y中的最大值与最小值,并将它们分别存入max和min元中。数据段的定义如下:.dataaray dword 12,4,168,122,33,56,78,99,345,66,5min dword ?max dword ?include io32.inc.dataaray dword 12,4,168,122,33,56,78,99,345,66,5min dword ?max dword ?promptbyteEnter an integers :,0maxStrbytemax=%d,13,10,0 ;显示字符串的格式描述串minStrbytemin=%d,13,10,0.codemainpro。

11、cmovecx,lengthof ara -1moveax,ara0;eax:maxmovebx,eax ;ebx,minmovesi,1again:cmpeax,araesi*4jgesmallmoveax,araesi*4small:cmpebx,araesi*4jlenextmovebx,araesi*4next:incesiloopagainmovmax,eaxmovmin,ebxret ;返回操作系统mainendpend main 5. 编程写一个完整的程序统计msg中的空格的个数与小写字母的个数,并分别将它们存入space单元与char单元中。数据段的定义如下:.datamsg 。

12、byte I love XUT !,13,10,0space dword ?char dword ?include io32.inc.datamsg byte I love XUT!,13,10,0space dword ?char dword ?.codemain procmov ebx,0xor edi,edimov esi,edil1: mov al,msgebxcmp al,20hjnz done1cmp al,0jz nextinc ediinc ebxjmp l1done1: cmp al,ajb done2cmp al,zja done2cmp al,0jz nextinc es。

13、iinc ebxjmp l1done2: cmp al,0jz nextinc ebx jmp l1next: mov space,edimov eax,spacecall dispuidcall dispcrlfmov char,esimov eax,charcall dispuidcall dispcrlfretmain endpend main6. 编程写一个完整的程序,将字符串msg中所有的小写字母转换为大写字母。数据段的定义如下:.datamsg byte I love XUT !,13,10,0include io32.inc.datamsg byte I love XUT!,13。

14、,10,0.codemain procmov ebx,0l1: mov al,msgebxcmp al,ajb donecmp al,zja donesub al,20hdone: cmp al,0jz done1inc ebxcall dispcjmp l1done1:retmain endpend main7. array是一无符号数数组,数据段的定义如下。要求:编程写一个完整的程序求出数组元素中偶数的和,并将它存入esum单元中。.dataarray dword 12,34,123,78,43,234,79,86,98,20esum dword ?算法描述:; 1. esum=0; 2.。

15、 for i=0 to n-1 do; if ai is evennunber then esum=esum+ai; 判断偶数,采用 test 指令测试最低位。; 合理分配寄存器:采用loop循环,ecx=lengthof array esum=eax=0,esi=0,做下标,采用带比例因子的相对寻址处理数组。include io32.inc.data array dword12,34,123,78,43,234,79,86,98,20esum dword ?fmtStr byte esum=%d,13,10,0 ;格式描述串.codemain procmovecx,lengthof arra。

16、yxor eax,eax ;esum=eax=0movesi,eax ;数组下标again: movebx,arrayesi*4testebx,1jnznext ;if ai is evennunber then esum=esum+ai;addeax,ebx ;注意:转换成汇编语言时,测试的是不是偶数时则取下一个数测试。next:incesiloopagainmovesum,eaxinvoke printf,offset fmtStr,esumret;return to Windowsmain endp ;end of mainend main ;end of assembly8. “回文串。

17、”是一个正读和反读都一样的字符串,比如“eye”、“level”、“noon”等。请写一个程序测试一字符串是否是“回文”, 是“回文”则显示“Y”,否则显示“N”。 显示一个字符的子程序为:dispc,入口参数:AL=要显示个字符的SACII码。; 算法描述:; left,right分别指向串的第一个和最后一个元素,采用首尾比较。; 1. left=0,right=n-1 ,flag=Y ;; 2. while leftaright- then ; flag= N; break; 3. printf flag; 合理分配寄存器:left=esi,right=edi ,flag=al=Yincl。

18、ude io32.inc.data msg byte level,0count equ lengthof msg.codemainprocmovesi,0 ;left指针movedi,count-2 ;right指针,串长不包括结束标志0moval,Y ; flag=al=Y.while(esi0)xor edx,edxdiv ebximul esi,10add esi,edx.endwcmp esi,ecxjne nextmov eax,ecxcall dispuid call dispcrlfnext: inc ecx.until(ecx10000)retmain endpend main。

19、10. 编程写一个名为Prime的子程序,用于测试一个整数是否是素数,主子程序间的参数传递通过堆栈完成。调用Prime子程序求出2100之间的所有素数,并将它们存入Parray数组中,素数的个数存入变量Pcounter中。; 采用伪代码pseudo code描述算法; 1. i=2 to 100 do; 1.1 if prime(i) then print i; 构造函数prime(i):; if i is prime number then prime(i)=1 else prime(i)=0; 合理分配寄存器,i=ebx,j=ecx,edxeax做被除数,ecx做除数.include io。

20、32.inc.datamsgbyte List of prime number,13,10,0msg1 byte pcounter is : ,13,10,0blankbyte ,0anyKey byte 13,10,press any key to continue .,13,10,0parray dword 100 dup(?)pcounter dword 0.codemainproc ;主程序开始mov esi,0moveax,offset msgcall dispmsgmovebx,2 ;i循环的初值.while (ebx0 do; r=a mod b;a=b;b=r; 2. gcd=。

21、a; 注意合理的分配使用寄存器,edx,eax做被除数; ebx=gcd的地址,eax=a,ecx=b pushebpmovebp,esp ; 建立访问栈参数的指针基准pusheax ; 保护子程序中要使用的寄存器pushebxpushecxpushedxmovebx,ebp+8 ;ebx=变量gcd的地址movecx,ebp+12 ;ecx=bmoveax,ebp+16 ;eax=a.while (ecx!=0)xoredx,edx ;被除数送edx,eax,32位除法divecx;div指令执行后eax=商,edx=余数moveax,ecx ;a=bmovecx,edx ;b=r,edx=。

22、余数.endwmovebx,eax ;gcd=最大公约数restore: popedx ; 恢复子程序中使用过的寄存器popecxpopebxpopeaxpopebpret 3*4 ;清理栈中的参数Gcd endp ;end of Gcdend main ;end of assembly12. 在一个已知长度的字符串中查找是否包含“BUG”子字符串。如果存在,显示“Y”,否则显示“N”。 显示一个字符的子程序为:dispc,入口参数:AL=要显示个字符的SACII码。include io32.inc.datastring byte If you find any error in the pr。

23、ogram, you can DEBUG it. count = sizeof string bug byte BUG .codestart:mov ecx,count mov edi,offset string L1: mov esi,offset bug push edi mov edx,sizeof bug LN: mov al,esi cmp edi,al jne L2 inc esi inc edi dec edx jne LN pop edi mov al,Y jmp L3 L2: pop edi inc edi loop L1 mov al,N L3: call dispcexi。

24、t 0end start13. 已知一个字符串的长度,剔除其中所有的空格字符。请从字符串最后一个字符开始逐个向前判断、并进行处理。include io32.inc.datastring byte Let us have a try !,0dh,0ah,0 .codestart:mov ecx,sizeof string cmp ecx,2 jb done lea eax,string ; 显示处理前的字符串 call dispmsg mov esi,ecx dec esi outlp: cmp stringesi, ; 检测是否是空格 jnz next ; 不是空格继续循环 mov edi,e。

25、si ; 是空格,进入剔除空格分支dec ecx inlp: inc edi mov al,stringedi ; 前移一个位置 mov stringedi-1,al cmp edi,ecx jb inlp next: dec esi ; 继续进行 cmp esi,0 jnz outlp ; 为0结束 lea eax,string ; 显示处理后的字符串 call dispmsg done: exit 0end start14. 编写一子程序,将一个32位二进制数用8位十六进制形式在屏幕上显示出来。采用堆栈方法传递这个32位二进制数,并写主程序验证它。显示一个字符的子程序为:dispc,入口参。

26、数:AL=要显示个字符的SACII码。.include io32.inc.datawvar dword AFH .codestart:push wvar call disp add esp,4 mov al,H call dispc disp proc push ebp mov ebp,esp push ebx push ecx mov ecx,8 mov eax,ebp+8 dhw1: rol eax,4 mov ebx,eax and al,0fh ; 转换为ASCII码 add al,30h cmp al,9 jbe dhw2 add al,7 dhw2: call dispc mov 。

27、eax,ebx loop dhw1 pop ecx pop ebx pop ebp ret disp endp exit 0end start15. 编程写一个名为Bubble的冒泡排序子程序,主子程序间的参数传递通过堆栈完成;并写主程序验证它。显示一个无符号数的子程序为:dispuid,入口参数:EAX=要显示无符号数的值。.include io32.incdataarray dword 12,4,168,122,-33,56,78,99,345,66,-5count equ lengthof arrayfmtStr byte %5d.codemain proc pushoffset arr。

28、ay ;array的首地址进栈,传地址push count ;数组元素的个数进栈,传值call Bubblexor esi,esi ;以下的while循环用于验证。可以删掉.while (esi0; esi=array;数组的首地址; ebx=ecx; while ebx0; if esiesi+4 then; swap esi,esi+4 ; esi=esi+4;ebx-; ; ecx-;pushebpmovebp,esp ; 建立访问栈参数的指针基准pusheax ; 保护子程序中要使用的寄存器pushebxpushecxpushesi pushedimovesi,ebp+12 ;arra。

29、y的首地址movedi,esimovecx,ebp+8 ;数组元素的个数dececxagain: movesi,edi ;esi=array的首地址movebx,ecx.while (ebx0)moveax,esicmpeax,esi+4 ; 比较两个相邻的元素jlnextxchgeax,esi+4movesi,eax ; 交换两个相邻的元素next: addesi,4 ; esi指向下一个元素decebx.endwloop againrestore: popedi ; 恢复子程序中使用过的寄存器popesipopecxpopebxpopeaxpopebpret 2*4 ;清理栈中的参数Bubble endp ;end of Bubbleend main ;end of assembly。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值