MIPS入门分析.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
MIPS入门分析

Review Memory transfer: lw, sw, lb, sb 判断语句可以使我们在运行时决定去执行哪部份代码,而无非编译时. C 使用条件分支 conditional statements语句来做决定, within if, while, do while, for. MIPS 中做决定的语句是 conditional branches: beq and bne. Unsigned add/sub don’t cause overflow New MIPS Instructions: beq, bne, j, sll, srl addu, addiu, subu, Loops Review Key Concept: 虽然现在在MIPS中有很多方法来实现循环, 但最重要的一点是:所有这些方法都使用条件分支 conditional branch do {g= g + A[i]; i= i + j; } while (i != h); Loop: g = g + A[i]; i = i + j; if (i != h) goto Loop; Inequalities in MIPS (1/3) Until now, we’ve only tested equalities (== and != in C). General programs need to test and as well. Create a MIPS Inequality Instruction: “Set on Less Than” Syntax: slt reg1,reg2,reg3 Meaning: if (reg2 reg3) reg1 = 1; else reg1 = 0; In computereeze, “set” means “set to 1”, “reset” means “set to 0”. Inequalities in MIPS (2/3) How do we use this? Compile by hand: if (g h) goto Less; #g:$s0, h:$s1 Answer: compiled MIPS code… slt $t0,$s0,$s1 # $t0 = 1 if gh bne $t0,$0,Less # goto Less # if $t0!=0 # (if (gh)) Less: Branch if $t0 != 0 ? (g h) Register $0 always contains the value 0, so bne and beq often use it for comparison after an slt instruction. A slt ? bne pair means if(… …)goto… Inequalities in MIPS (3/3) Now, we can implement , but how do we implement , ≤ and ≥ ? We could add 3 more instructions, but: MIPS goal: Simpler is Better Can we implement ≤ in one or more instructions using just slt and the branches? What about ? What about ≥? Immediates in Inequalities There is also an immediate version of slt to test against constants: slti Helpful in for loops if (g = 1) goto Loop Loop: . . . slti $t0,$s0,1 # $t0 = 1 if # $s01 (g1) beq $t0,$0,Loop # goto Loop # if $t0==0 # (if (g=1)) What about unsigned numbers? Also unsigned inequality instructions: sltu, sltiu …which sets result to 1 or 0 depending on unsigned comparisons What is value of $t0, $t1? ($s

文档评论(0)

yaocen + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档