资源描述:
《第三章 计算机组成原理》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Chapter:1,2,4,5,6,7,8,9,11,23,241.AddcommentstothefollowingMIPScodeanddescribeinonesentencewhatitcomputes.Assumethat$a0isusedfortheinputandinitiallycontainsn,apositiveinteger.Assumethat$v0isusedfortheoutput.begin:addi$t0,$zero,0#$t0=0addi$t1,$zero,1#$t1=1loop:slt$t2,$
2、a0,$t1#$t2=1if$a0<$t1bne$t2,$zero,finish#if$a0<$t1,jumptofinishadd$t0,$t0,$t1#$t0=$t0+$t1addi$t1,$t1,2#$t1=$t1+2jloop#jumptoloopfinish:add$v0,$t0,$zero#return$t0AsampleCprogram:intf(intn){inti=0;intj=1;while(n>=i){i=i+j;j+=2;}returni;}2.Thefollowingcodefragmentprocess
3、esanarrayandproducestwoimportantvaluesinregisters$v0and$v1.Assumethatthearrayconsistsof5000wordsindexed0through4999,anditsbaseaddressisstoredin$a0anditssize(5000)in$a1.Describeinonesentencewhatthiscodedoes.Specifically,whatwillbereturnedin$v0and$v1?Findtheelementwhich
4、appearsmosttimes,$v0storesthethemaxiumnumberoftheidenticalintegerinthearray,$v1storesitsvalue.4.ShowthesingleMIPSinstructionorminimalsequenceofinstructionsforthisCstatement:a=b+100;;Assumethatacorrespondstoregister$t0andbcorrespondstoregister$t1.addi$t0,$t1,1005.Showt
5、hesingleMIPSinstructionorminimalsequenceofinstructionsforthisCstatement:x[10]=x[11]+c;Assumethatccorrespondstoregister$t0andthearrayxhasabaseaddressof4,000,000ten.4,000,000ten=11,1101,0000,1001,0000,0000twolui$t1,61addi$t1,$t1,2304lw$t2,44($t1)add$t2,$t2,$t0sw$t2,40($
6、t1)4.Thefollowingprogramtriestocopewordsfromtheaddressinregister$a0totheaddressinregister$a1,countingthenumberofwordscopiedinregister$v0.Theprogramstopscopyingwhenitfindsawordequalto0.Youdonothavetopreservethecontentsofregisters$v1,$a0,and$a1.Thisterminatingwordshould
7、becopiedbutnotcounted.loop:lw$v1,0($a0)#Readnextwordfromsourceaddi$v0,$v0,1#Incrementcountwordscopiedsw$v1,0($a1)#Writetodestinationaddi$a0,$a0,1#Advancepointertonextsourceaddi$a1,$a1,1#Advancepointertonextdestbne$v1,$zero,loop#Loopifwordcopied≠zeroLoop:lw$v1,0($a0)#R
8、eadnextwordfromsourcesw$v1,0($a1)#Writetodestinationaddi$a0,$a0,4#Advancepointertonextsourceaddi$a1,$a1,4#Advancepointertone