• You are responsible for chapter 1 and Appendix B (up to, but not including B.6)
  • You should now read chapter 2 now too.
  • We have been dancing in and out of this chapter.
  • The table on page 78 is extremely useful, and you will see why now.
  • In the book, they give us 4 design principles. Learn these:
    • Simplicity favors regularity.
    • Smaller is faster
    • Make the common case fast
    • Good design demands good compromises.
  • You should be able to provide examples/discuss each of theses.
  • All instructions (when possible)
    • opcode destination, source, source
    • This is clear in the R type instructions (most of them at least)
    • add $R1, $R2, $R3 : R1 <- R2 + R3
    • This is an example of the first principle, Simplicity favors regularity.
    • If we look at the machine on 322, we see that there is no decision on where the first source of (most) instructions.
    • It is always bits 25-21
  • How do we encode something like a=b*(c+d)-h*(f+g)
  • Design principle 2, Smaller is faster.
    • An example is the number of registers.
    • Why 32?
    • What do we use registers for?
    • What happens when we run out of registers?
    • What happens if we add more registers?
    • Why 32, why not 31, 27, 17?
  • notice, All examples so far have included principle 4.
  • We will see another example of this (smaller is faster) when we get to circuits.
  • Memory operations.
    • lw $rd, imm($rs)
    • This will fetch the data at memory imm+$rs and store it in $rd
    • For simple variables, the immediate is stored in the address.
    • This is normally associated with a .word directive
        This make sure that the data is word aligned.
      • 	.data
        var1:	.word 3
        ...
        	.text
        	lw	$t1, var1($zero)
               
      • For an array, we will need more space reserved.
      • This can be done with
        ary:	.word 9 8 7 6 5 4 3 2 1
               
      • Or a blank array can be built
        ary2:	.space 40
               
      • We need to make sure that it starts on a word boundary
        • this one will because everything above it was on a word boundary
        • We can specify word alignment with the .align 2 directive
      • Notice that the size is a multiple of 4
        • .space allocates bytes, and words are needed here.
      • Loading array elements
        • Normally the array address is the base address
        • The register is used to index into the array, or the array offset
        • 	li	$t5, 0
          top:
          	lw 	$t3, ary($t5)
          	addi	$t5, $t5, 4
          	blt	$t5, 40, top
          	   
    • sw is the same general principle
    • As are the half word, and byte instructions.
    • As are the unsigned.