Concepts Introduced in Chapter 3 basic instruction set design principles subset of the MIPS assembly language correspondence between high-level language constructs and MIPS assembly code how MIPS assembly instructions are represented in machine language stored-program concept process of transforming a high-level language program into a program that can execute on a computer Chapter 3: Instructions: Language of the Machine - 1 of 35
Instructions for a Machine High-Level Language Statement is typically represented by several assembly instructions Assembly Instruction is generally a symbolic representation of a machine instruction Machine Instruction a sequence of bits representing a basic operation that a machine can perform Instruction Set is the set of possible machine instructions for a specific machine Chapter 3: Instructions: Language of the Machine - 2 of 35
Figure 3.21: A translation hierarchy. Chapter 3: Instructions: Language of the Machine - 3 of 35
Goals When Designing an Instruction Set Make hardware easy to build. Make the compiler easy to construct. Maximize performance. Minimize cost. Chapter 3: Instructions: Language of the Machine - 4 of 35
Memory Chapter 3: Instructions: Language of the Machine - 5 of 35
Registers Chapter 3: Instructions: Language of the Machine - 6 of 35
Instruction Set Design Principles Simplicity favors regularity. Smaller is faster. Good design demands good compromises. Make the common case fast. Chapter 3: Instructions: Language of the Machine - 7 of 35
Who Programs in Assembly Language? Most programming today is done in a high-level language (e.g. C++). However, there are some programs that are written in assembly code. critical parts of an operating system (e.g. device drivers) run-time library routines (e.g. printf) embedded applications Chapter 3: Instructions: Language of the Machine - 8 of 35
Why Learn Assembly Language? to understand concepts in computer organization to understand how high-level language constructs are actually implemented control constructs (if, while-do, etc.) parameter passing (pass-by-value, pass-by-reference, etc.) pointers to help understand performance implications Chapter 3: Instructions: Language of the Machine - 9 of 35
MIPS Introduction The MIPS is a RISC (Reduced Instruction Set Computer) instruction set. It was introduced in the early 1980 s. Many instruction sets designed since that time are very similar. The MIPS architecture has been used by SGI, NEC, Nintendo, etc. Chapter 3: Instructions: Language of the Machine - 10 of 35
General Classes of MIPS Assembly Instructions Arithmetic perform arithmetic operations (+, -, *, /) Logical perform logical operations (&,, <<, >>) Data Transfer loads from memory or stores to memory Transfers of Control transfers control from one portion of the program to another Chapter 3: Instructions: Language of the Machine - 11 of 35
MIPS Instruction Operands Integer Constants generally represented in 16 bits or less Registers $0 hardwired to contain the value zero $1,$26-$29 reserved by the assembler or the operating system (don t use them) $2-$25, $30, $31, $f0-$f31 for use by the compiler or assembly language programmer Memory [0..2**32-1] bytes or [0..2**30-1] words Chapter 3: Instructions: Language of the Machine - 12 of 35
General Form of a MIPS Assembly Language Program Chapter 3: Instructions: Language of the Machine - 13 of 35
General Form of a MIPS Instruction Chapter 3: Instructions: Language of the Machine - 14 of 35
General Forms of a MIPS Arithmetic or Logical Instruction Chapter 3: Instructions: Language of the Machine - 15 of 35
General Form of a MIPS Data Transfer Instruction Chapter 3: Instructions: Language of the Machine - 16 of 35
Example of Using Arithmetic/Logical and Data Transfer Instructions Chapter 3: Instructions: Language of the Machine - 17 of 35
Another Example Using Arithmetic/Logical and Data Transfer Instructions Chapter 3: Instructions: Language of the Machine - 18 of 35
Memory Access Issues There are alignment restrictions based on the size of the data being accessed. Byte xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Half xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0 Word xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx00 Double xxxxxxxxxxxxxxxxxxxxxxxxxxxxx000 Chapter 3: Instructions: Language of the Machine - 19 of 35
Memory Access Issues (cont.) Chapter 3: Instructions: Language of the Machine - 20 of 35
General Form of MIPS Transfer of Control Instructions Chapter 3: Instructions: Language of the Machine - 21 of 35
Translating an If-Then-Else Statement into MIPS Assembly Instructions Chapter 3: Instructions: Language of the Machine - 22 of 35
Translating a For Statement into MIPS Assembly Instructions Chapter 3: Instructions: Language of the Machine - 23 of 35
Instruction Formats Chapter 3: Instructions: Language of the Machine - 24 of 35
Figure 3.37: The MIPS instruction set covered so far. Chapter 3: Instructions: Language of the Machine - 25 of 35
Examples of Encoding Instructions Chapter 3: Instructions: Language of the Machine - 26 of 35
Encoding the Branch Displacement Chapter 3: Instructions: Language of the Machine - 27 of 35
lui Instruction Chapter 3: Instructions: Language of the Machine - 28 of 35
Figure 3.17: Illustration of the five MIPS addressing modes. Chapter 3: Instructions: Language of the Machine - 29 of 35
Figure 3.7: The stored-program concept. Chapter 3: Instructions: Language of the Machine - 30 of 35
Figure 3.21: A translation hierarchy. Chapter 3: Instructions: Language of the Machine - 31 of 35
Figure 3.22: The MIPS memory allocation for program and data. Chapter 3: Instructions: Language of the Machine - 32 of 35
Figure 3.12: Illustration of the stack allocation (a) before, (b) during, and (c) after the procedure call. Chapter 3: Instructions: Language of the Machine - 33 of 35
Figure 3.13: MIPS register convention. Chapter 3: Instructions: Language of the Machine - 34 of 35
Fallacies and Pitfalls Fallacy: More powerful instructions mean higher performance. Fallacy: Write in assembly language to obtain the highest performance. Pitfall: Forgetting that sequential word addresses in machines with byte addressing do not differ by one. Pitfall: Using a pointer to an automatic variable outside its defining procedure. Chapter 3: Instructions: Language of the Machine - 35 of 35