资源描述:
《MIPS编程实例集锦.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、PROBLEMSINMIPSPROGRAMMING·Howtowriteaprogramtoaddallpositivenumbersonce&allnegativenumbersonce?·Writeaprogramtodisplaytheprimenumbersbetween1to1000?·ProgramtowriteFibonacciusingrecursion?·Writeaprogramtoswapthe2strings?·Writeaprogramtoreverseofgivenstrin
2、g?·Writeaprogramtomultiply2numbers(eg128*256)?·Writeaprogramtoconvertgivennumberintootherbase?(eg:givennumberindecimalconvertingtobaselike2itisbinarysoitconvertsdecimaltobinary)·Writeaprogramtoconvert“COMPUTERORGANISATION”tolowercase?·Writeprogramtobubbl
3、esortofthegivennumbers?·Writeaprogramtocomparingstringswhetherornot?·Writeaprogramconvertlowercaseletterstouppercaseletters?·Writeaprogramformultiplicationtable?·Writeaprogramtofindgivennumberisevenorodd?·Writeaprogramforpalindromenumber?·Writingprogramf
4、orraisingpower?·Writeaprogramforsumof3integers?1)Howtowriteaprogramtoaddallpositivenumbersonce&allnegativenumbersonce?Code:.dataarray:.word-4,5,8,-1msg1:.asciiz"Thesumofthepositivevalues="msg2:.asciiz"Thesumofthenegativevalues=".globlmain.textmain:li
5、$v0,4#systemcallcodeforprint_strla$a0,msg1#loadaddressofmsg1.into$a0syscall#printthestringla$a0,array#InitializeaddressParameterli$a1,4#InitializelengthParameterjalsum#Callsummove$a0,$v0#movevaluetobeprintedto$a0li$v0,1#systemcallcodeforprint_intsyscall#
6、printsumofPos:li$v0,4#systemcallcodeforprint_strla$a0,msg2#loadaddressofmsg2.into$a0syscall#printthestringli$v0,1#systemcallcodeforprint_intmove$a0,$v1#movevaluetobeprintedto$a0syscall#printsumofnegli$v0,10#terminateprogramrunandsyscall#returncontroltosy
7、stemsum:li$v0,0li$v1,0#Initializev0andv1tozeroloop:blez$a1,retzz#If(a1<=0)BranchtoReturnaddi$a1,$a1,-1#Decrementloopcountlw$t0,0($a0)#Getavaluefromthearrayaddi$a0,$a0,4#Incrementarraypointertonextwordbltz$t0,negg#IfvalueisnegativeBranchtoneggadd$v0,$v0,$
8、t0#Addtothepositivesumbloop#Brancharoundthenexttwoinstructionsnegg:add$v1,$v1,$t0#Addtothenegativesumbloop#Branchtoloopretzz:jr$ra#ReturnOutput:1)WriteaProgramfactorialofagivennumber?.textfact:#ALLOCATEAFRAMEFORTHEDYNAMICL