cpsc161lecture3内容摘要:
f=(g+h)(i+j) .8 1999169。 UCB MIPS Instruction Encoding Examples of some Opcodes: Instruction Format Opcode shamt funct Add R 0 0 32 Sub R 0 0 34 Shift (by 4) R 0 4 0 Add (imm) I 8 Lw (load word) I 35 Sw (store word) I 43 .9 1999169。 UCB Data Transfer Instruction: Memory to Reg 176。 Load: moves data from memory to register •Syntax: 1) operation name 2) register to be loaded 3) constant and register to access memory 176。 MIPS name, lw for load word: •Example: lw $t0, 8($s3) Called “offset” Called “base register” or “base address register” or “base address” .10 1999169。 UCB Compilation when Operand is in Memory Q: Compile by hand using registers: g = h + A[300]。 g:$s1, h:$s2, $s3:starting (base) address of array A 176。 Since A[300] is in memory, 1st transfer from memory to (temporary) register: lw $t0,300($s3) Adds 300 to $s3 to select A[300], puts into $t0 lw $t0,1200($s3) For byte addressable machines 300x4 176。 Next add it to h and place in g add $s1,$s2,$t0 $s1= h+A[300] HW: Compile A[300] = h + A[300] .11 1999169。 UCB Tanslating to MIPS Machine Language 176。 From the instruction set, Opcode for Lw is 35. Opcode for add is 0 with funct 32. 176。 From register assignment table, t0=8, s1=17, s2=18 and s3=19. 176。 Instruction consists of op=5 bits, rs=5bits, rt=5bits, rd=5bits, shamt=5bits and funct=6bits for R format and address=16 bits instead of rd,shamt and funct for I format: total=32 bits Assembly language lw $t0, 1200($s3) and add $s1,$s2,$t0 translate to: op | rs | rt | rd | address/shamt | funct | 35 | 19 | 8 | 1200 | 0 | 18 | 8 | 17 | 0 | 32 | .12 1999169。 UCB Compile with variable index 176。 What if array index not a constant? g = h + A[i]。 • g:$s1, h:$s2, i:$s4, $s3:base address of A 176。 To load A[i] into a register, first turn i into a byte address。 multiply by 4 176。 How multiply using adds? •i + i = 2i, 2i + 2i = 4i add $t1,$s4,$s4 $t1 = 2*i add $t1,$t1,$t1 $t1 = 4*i .13 1999169。 UCB Compile with variable index, con’t 176。 Next add to base of A: add $t1,$t1,$s3 $t1=ad。cpsc161lecture3
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。