03-More-MIPS-instructions

03-More-MIPS-instructions - More MIPS instructions Last...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
January 29, 2003 ©2001-2003 Howard Huang 1 More MIPS instructions ± Last time we introduced the MIPS instruction set architecture, with its three-address instructions and dedicated loads and stores. ± Today we’ll go into more detail about the ISA. — Constant values can be embedded in instructions. — Pseudo-instructions make programming easier for people. — Branches and jumps alter a program’s control flow. ± We also discuss the binary representation of MIPS instructions. — This will reveal some restrictions on certain instructions. — We’ll see workarounds for all of the limitations.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
January 29, 2003 More MIPS instructions 2 Immediate operands ± The ALU instructions we’ve seen so far expect register operands. How do you get data into registers in the first place? $0 , or $zero , is a dedicated register which always contains 0 and cannot be modified. (Go ahead and try.) add $t0, $0, $0 # $t0 = 0 — Some MIPS instructions allow you to specify a signed constant, or immediate value, for the second source instead of a register. For example, here is the immediate add instruction, addi : addi $t0, $t1, 4 # $t0 = $t1 + 4 ± MIPS is still considered a load/store architecture, because arithmetic operands cannot be from arbitrary memory locations. They must either be registers or constants that are embedded in the instruction.
Background image of page 2
January 29, 2003 More MIPS instructions 3 Immediate examples ± We can use constant operands and $0 to initialize registers or to copy data between registers. addi $a0, $0, 2000 # Initialize $a0 to 2000 add $a1, $t0, $0 # Copy $t0 into $a1 ± Here is a short example which sets the first two words of an array to 0 and 23, where the array starts at address 2000. addi $a0, $0, 2000 # Initialize $a0 to 2000 sw $0, 0($a0) # Store 0 in address 2000 addi $t0, $0, 23 # Set $t0 = 23 sw $t0, 4($a0) # Store 23 in address 2004
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
January 29, 2003 More MIPS instructions 4 Pseudo-instructions ± MIPS assemblers support pseudo-instructions that give the illusion of a more expressive instruction set, but are actually translated into one or more simpler, “real” instructions. ± For example, you can use the li and move pseudo-instructions: li $a0, 2000 # Load immediate 2000 into $a0 move $a1, $t0 # Copy $t0 into $a1 ± They are probably clearer than the MIPS instructions we just saw: addi $a0, $0, 2000 # Initialize $a0 to 2000 add $a1, $t0, $0 # Copy $t0 into $a1 ± We’ll see lots more pseudo-instructions this semester. — A complete list of instructions is given in Appendix A of the text. — Unless otherwise stated, you can always use pseudo-instructions in your assignments and on exams.
Background image of page 4
January 29, 2003 More MIPS instructions 5 Control flow in high-level languages ± The instructions in a program usually execute one after another, but it’s often necessary to alter the normal control flow. ± Conditional statements execute only if some test expression is true.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2012 for the course CS 251 taught by Professor Howardhuang during the Fall '09 term at Waterloo.

Page1 / 22

03-More-MIPS-instructions - More MIPS instructions Last...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online