ImageVerifierCode 换一换
格式:DOCX , 页数:33 ,大小:32.55KB ,
资源ID:8594790      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8594790.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(常见汇编程序源代码示例.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

常见汇编程序源代码示例.docx

1、常见汇编程序源代码示例包含14个常见的汇编程序源代码,所有代码在VC6.0中调试通过;汇编程序釆用微机原理接口与技术(钱晓婕)一书中所用的框架。1.编写程序,计算下面函数的值并输出。 22.输入一个年份(调用readuid子程序),判断是否是闰年 23.输入三个无符号整数(调用readuid子程序),判断并输出这三个数是否能构成一个三角形的三条边。若这三个数能构成一个三角形的三条边,输出三角形的形 状:斜三角形、等腰三角形、等边三角形。 34.采用无条件和条件转移指令构造while和do while循环结构,完成下面的求和任务并输出sum(sum为双字)。 55.编写程序,求0到100间所有偶

2、数和并输出。要求采用loop、while# do while三种不同的循环结构完成。 66.Fibonacci numbers 的定义: 8fl=l,f2=lz fn= fn-1 + fn-2 n=3 8编程输出Fibonacci numbers的前30 项。 87.有一个首地址为array的20个有符号的双字数组,编程分别求出正数的和与负数的和并输出。 108.有一个首地址为string的字符串,剔除string中所有的空格字符。请从字符串最后一个字符开始逐个向前判断、并进行处理。 129.有一个首地址为string的字符串,分别统计string中空格、英文字母、数字和其它字符的个数并输出。

3、 1310.palindrome(回文)是指正读和反读都一样的数或文本。例如:11、121. 12321 等,编写程序,求10到10000之间所有回文数并输出。要求每行输出10个数。1511.编写程序,求出所有满足勾股定理且边长不大于500的直角三角形。.1712.编写一个求n!的子程序,利用它求1 !+2!+引+4!+5!+6!+7!+8!的和并输出。2213.编写一个判断闰年的子程序,利用它求出2010年到2060年之间所有的闰年并输出。 2514.编写一个求解双字型有符号数数组元素的平均值子程序,并验证它的正确 性。261.编写程序,计算下面函数的值并输出。2x (x 0)s = 3x

4、(0 = x 10in elude io32.i nc.codestart:call readsidemp eax,0jl smallemp eax,10jle midjmp largesmall:imul eax,2jmp donemid:imul eax,3jmp donelarge:imul eax,4jmp donedone:call dispsidexit 0end start2输入一个年份(调用readuid子程序),判断是否是闰年.in elude io32.i nc.datayes_msg byte is leap:13,10,0no_msg byte no leap,13,1

5、0,0.codestart:call readuidmov edx,0mov ecx,4div ecxemp edx,0je firstjmp secondfirst:mov edx,0mov ecx,100div ecxjne leapjmp secondsec ond:mov edx,0mov ecx,400div ecxje leapjmp noleapleap:mov eax,offset yes_msgcall dispmsgjmp donenoleap:mov eax,offset no_msgcall dispmsgjmp donedone:exit 0end start3输入三

6、个无符号整数(调用readuid子程序),判断并输出这三个数是否能 构成一个三角形的三条边。若这三个数能构成一个三角形的三条边,输出三 角形的形状:斜三角形、等腰三角形、等边三角形。in elude io32.i nc.datamsgdengyao byte dengyao:13,10,0 ;等腰三角形msg_dengbian byte dengbian,13,10,0 ;等边三角形msg_zhijiao byte zhijiao,13,10,0 ;直角三角形msg_xiesanjiao byte xiesanjiaoxing:13J0,0;斜三角形msgwrong byte wrong: 1

7、3,10,0 ;无法构成三角形sqr dword 0.code;在ebx,ecx,edx分别保存三条边的长度start:call readuid ;读取第一个数和第二个数到ebx、ecxmov ebx,eaxcall readuidmov ecx,eax cmp ebx,ecx jg great jmp nextgreat:xchg ebx,ecxnext:call readuidmov edx,eax cmp ebx,edx jg thirdsmall cmp ecx,edx jg thirdmid jmp order ;如果第三个数最小 thirdsmall:mov eax,edxmov

8、edx,ecxmov ecx,ebxmov ebx,eaxjmp order;如果第三个数在最中间 thirdmid:xchg ecx,edxjmp order;确保 ebx=3 编程输出Fibonacci numbers的前30项。in elude io32.i nc.dataspace byte :0;输出空格fl dword 1 ;fn-lf2 dword 1 ;fn-2.codestart:;输出fl;输出f2mov ecx,30 mov eax,fl call disp dec ecx mov eax,f2 call dispdec ecxagai n:mov eax,fl add

9、eaxzf2 call disp mov ebx,f2 mov fl,ebx mov f2,eax loop again jmp done;eax = fn J + fn2;fn-l = fn-2;fn2 = eaxdisp procpush eax ;保护寄存器eaxcall dispuidmov eax,offset spacecall dispmsgpop eax ;恢复寄存器eaxretdisp endpdone:exit 0end start;结果:;1 123 58 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 109

10、46 17711 2 ;8657 46368 75025 121393 196418 317811 514229 832040 Press any key to continue思考题:在不产生溢出的情况下n的最大值是多少?in elude io32.i nc.dataspace byte 1 0maxn byte The Maximum n is 0 fl dword 1 f2 dword 1.codestart:xor ecx,ecx mov eax,fl call disp inc ecx mov eax,f2 call disp inc ecxagain:mov eax,fl add

11、eax,f2 jc done call disp mov ebx,f2 mov fl,ebx mov f2,eax inc ecx jmp againdisp procpush eax call dispuidmov eax,offset spacecall dispmsgpop eax;输出空格;fn-l;fn-2;输出fl;输出f2;eax = fn-1 + fn2 ;有进位时跳出;fn-l = fn-2;fn 2 = eax;输出过程retdisp endp done:call dispcrlfmov eax,offset maxn call dispmsg mov eax,ecx ca

12、ll dispuid call dispcrlfexit 0end start;运行结果:;1 123 58 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 2;8657 46368 75025 121393 196418 317811 514229 832040 134* *309 3524578 5702 ;887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 43 ;3494437 701408733

13、1134903170 1836311903 2971215073;The Maximum n is 47;Press any key to continue7.有一个首地址为array的20个有符号的双字数组,编程分别求出正数的 和与负数的和并输出。in elude io32.i nc.dataarray dword -1, 2, 4, -8, 6,-4,-9, & 4, 0,-49, 4,31,-6& 1,-4, 6, 5, 7, -51sumofpos dword ? sumofneg dword ? .codestart:mov ecxje ngthof array xor edx,ed

14、x;保存正数的和;保存负数的和;数组元素个数;数组下标;取出下标为edx的数组元素;所有求和结束again:mov eax,arrayedx*4 inc edxemp eax,0jg positive jl negativecon tinue:loop againjmp done positive:add sumofposzeax ;正数求和jmp continuenegative:add sumofneg,eax ;负数求和jmp continuedone:mov eax,sumofposcall dispsidcall dispcrlfmov eax,sum ofnegcall disps

15、idcall dispcrlfexit 0end start运行结果:78-194思考题:将求和改为求最大值与最小值。in elude io32.i nc.dataarray dword -1Z2Z 4, -8, 6,-4,-9, & 4, 0,-49, 4,31,-6& 1,-4, 6, 5, 7, -51 max dword ? ;最大值min dword ? ;最小值.codestart:mov eax,arrayOmov max,eaxmov min,eaxmov ecxjengthof array xor edx,edxagain:mov eax,arrayedx*4 inc edx

16、emp eax,maxjg .max;为max和min赋初值;数组元素个数;数组下标;取出下标为edx的数组元素emp eax,min jl _mi ncon tinue:loop again_max:mov max,eax jmp continue _min:mov min,eax jmp continue done:mov eax,max call dispsid call dispcrlf mov eax,min call dispsid call dispcrlf exit 0 end start 运行结果: 31-68&有一个首地址为string的字符串,剔除string中所有的空格

17、字符。请从 字符串最后一个字符开始逐个向前判断、并进行处理。in elude io32.i nc.datastring byte Let us have a try !:0 .codestart:mov eax,offset stringcall dispmsgcall dispcrlfmov esijengthof stringdec esiagain:mov al,stringesiemp al/jz reject dec esijl done jmp again;测试字符串;输出字符串;esi为数组长度;esi指向最后一个元素湯U除空格;循坏结束reject:mov ecx,esirej

18、ectl:mov alstringlecx+1 mov stringecx,al test alzal jz againinc ecxjmp rejectldone:mov eax,offset string call dispmsg call dispcrlfexit 0end start;ecx指向当前找到的空格;将后续字符依次往前移;遇到0结尾;完成一个空格的剔除;继续前移后一个字符;运行结果:;Let us have a try !;Letushaveatry!9.有一个首地址为string的字符串,分别统计string中空格、英文字母、 数字和其它字符的个数并输出。in elude

19、io32.i nc.datastring byte Let us hava a try. 123,Go!:0 ;测试字符串countofspace dword ? ;空格countofletter dword ? ;英文字母countofdigit dword ? ;数字countofother dword ? ;其他.code start:;字符数组卜标xor edx,edxagain:mov al,stringedxemp al,0 jz done emp al/ jz spaceemp al/a* jge letterjower con tinue_upper:;遇到0结束;判断空格;初

20、步判断为小写字母cmp al/A1jge letter_upper con tinue_digit:cmp al/01jge digitOcon tinue_other:inc countofothercon tinue:inc edxjmp again space:inc countofspace jmp continueletterjower:cmp al/z1 jle lower jmp continue_upper lower:inc countofletter jmp continueletter_upper: cmp al/Z* jle upper jmp continue_dig

21、it upper:inc countofletterjmp continuedigitO:cmp al/91 jle digit9 jmp continue_other digit9:inc countofdigit jmp continue;依次输出空格数、英文字母数、 done:mov eax,co un tofspacecall dispuidcall dispcrlfmov eax,co un tofletter;初步判断为人写字母;初步判断为数字;其他字符;增加下标号,开始下一次循坏;进一步判断是否为小写字母;继续判断是否人写字母 ;确定为小写字母;进一步判断是否为人写字母;继续判断

22、是否为数字;确定为大写字母;进一步判断是否数字;只能是其他字符数字、其他、call dispuidcall dispcrlfmov eax,co unto fdigitcall dispuidcall dispcrlfmov eax,co un tofothercall dispuidcall dispcrlfexit 0end start;运行结果:;5;15;3;510. palindrome(回文)是指正读和反读都一样的数或文本。例如:11、121. 12321等,编写程序,求10到10000之间所有回文数并输出。要求每行输 出10个数。提示:采用div指令把整数分解为单个的数字,并将它

23、们组合成一个新的整数。in elude io32.i nc.datastring byte 0,0,0,0,0chushu dword 10 back dword ?count dword ?.codestart:mov eax,10outlp:;保存转换后的字符串(逆序方式);除数10,用于提取个位数字;备份eax寄存器的值;计算以输出的总数,用于每10个换行;eax 从 10 到 10000mov ecx,0 mov back,eax;ecx清零,用于记录字符串实际长度;备份eax寄存器的值DigitToString:;将数字转换成字符串xor edx,edx div chushu add dl,30h mov strin gecx,dl inc ecxtest eax,

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1