文档介绍:
SolutionsChapter2Exercise2.4ThefollowingproblemsdealwithtranslatingfromCtoMIPS.Assumethatthevariablesf,g,h,i,andjareassignedtoregisters$s0,$s1,$s2,$s3,and$s4,respectively.AssumethatthebaseaddressofthearraysAandBareinregisters$s6and$s7,respectively.a.f=-g-A[4];b.B[8]=A[i-j]2.4.1FortheCstatementabove,whatisthecorrespondingMIPSassemblycode?Solution:a.lw$s0,16($s6)sub$s0,$0,$s0sub$s0,$s0,$s1b.sub$t0,$s3,$s4slli$t0,$t0,2add$t0,$s6,$t0lw$t1,0($t0)sw$t1,32($s7)2.4.2FortheCstatementsabove,howmanyMIPSassemblyinstructionsareneededtoperformtheCstatement?Solution:a.3b.52.4.3FortheCstatementabove,howmanydifferentregistersareneededtocarryouttheCstatement?Solution:a.3b.6ThefollowingproblemsdealwithtranslatingfromMIPStoC.Assumethatthevariablesf,g,h,i,andjareassignedtoregisters$s0,$s1,$s2,$s3,and$s4,respectively.AssumethatthebaseaddressofthearraysAandBareinregisters$s6and$s7,respectively.a.slli$s2,$s4,1//h=j*2add$s0,$s2,$s3//f=j*2+iadd$s0,$s0,$s1//f=j*2+i+gb.add$t0,$s6,$s0//t0=&A[f/4]add$t1,$s7,$s1//t1=&B[g/4]lw$s0,0($t0)//s0=A[f/4]addi$t2,$t0,4//t2=&A[f/4+1]lw$t0,0($t2)//t0=A[f/4+1]add$t0,$t0,$s0//t0=A[f/4]+A[f/4+1]sw$t0,0($t1)//B[g/4]=A[f/4]+A[f/4+1]2.4.4FortheMIPSassemblyinstructionsabove,whatisthecorrespondingCstatement?Solution:a.f=2j+i+g;b.B[g]=A[f]+A[1+f];2.4.5FortheMIPSassemblyinstructionsabove,rewritetheassemblycodetominimizethenumberifMIPSinstructions(ifpossible)neededtocarryoutthesamefunction.Solution:a.slli$s2,$s4,1add$s0,$s2,$s3add$s0,$s0,$s1b.add$t0,$s6,$s0add$t1,$s7,$s1lw$s0,0($t0)lw$t0,4($t0)add$t0,$t0,$s0sw$t0,0($t1)2.4.6HowmanyregistersareneededtocarryouttheMIPSassemblyaswrittenabove?Ifyoucouldrewritethecodeabove,whatistheminimalnumberofregistersneeded?Solution:a.5aswritten,5minimallyb.7aswritten,6minimallyExercise2.6ThefollowingproblemsdealwithtranslatingfromCtoMIPS.Assumethatthevariablesf,g,h,i,andjareassignedtoregisters$s0,$s1,$s2,$s3,and$s4,respectively.AssumethatthebaseaddressofthearraysAandBareinregisters$s6and$s7,respectively.AssumethattheelementsofarraysAa
内容来自淘豆网www.taodocs.com转载请标明出处.