ppt讲解计算机的组成,计算机结构与组成习题讲解chapter 2.ppt

本文提供了从C语言到MIPS汇编语言的翻译实例,包括变量操作与数组访问的转换。详细介绍了每条C语句对应的MIPS指令,并讨论了所需的寄存器数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文档介绍:

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转载请标明出处.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值