instruction set
play

Instruction Set The repertoire of instructions of a computer - PDF document

The University of Adelaide, School of Computer Science 8 March 2012 2.1 Introduction Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets


  1. The University of Adelaide, School of Computer Science 8 March 2012 §2.1 Introduction Instruction Set � The repertoire of instructions of a computer ��������� � Different computers have different instruction sets ����������������������� � But with many aspects in common ��������������� � Early computers had very simple instruction sets � Simplified implementation � Many modern computers also have simple instruction sets Chapter 2 — Instructions: Language of the Computer — 2 §2.2 Operations of the Computer Hardware The MIPS Instruction Set Arithmetic Operations � Used as the example throughout the book � Add and subtract, three operands � Stanford MIPS commercialized by MIPS � Two sources and one destination Technologies (www.mips.com) ��������������������������� � Large share of embedded core market � All arithmetic operations have this form � Applications in consumer electronics, network/storage � Design Principle 1: Simplicity favours equipment, cameras, printers, … � Typical of many modern ISAs regularity � See MIPS Reference Data tear-out card, and � Regularity makes implementation simpler Appendixes B and E � Simplicity enables higher performance at lower cost Chapter 2 — Instructions: Language of the Computer — 3 Chapter 2 — Instructions: Language of the Computer — 4 §2.3 Operands of the Computer Hardware Arithmetic Example Register Operands � Arithmetic instructions use register � C code: operands ������������� �������� � MIPS has a 32 × 32-bit register file � Use for frequently accessed data � Compiled MIPS code: � Numbered 0 to 31 �������������������������������� � 32-bit data called a “word” �������������������������������� � Assembler names ������������������������� �� � $t0, $t1, …, $t9 for temporary values � $s0, $s1, …, $s7 for saved variables � Design Principle 2: Smaller is faster � c.f. main memory: millions of locations Chapter 2 — Instructions: Language of the Computer — 5 Chapter 2 — Instructions: Language of the Computer — 6 Chapter 2 — Instructions: Language of the Computer 1

  2. The University of Adelaide, School of Computer Science 8 March 2012 Register Operand Example Memory Operands � Main memory used for composite data � C code: � Arrays, structures, dynamic data ������������� �������� � To apply arithmetic operations � f, …, j in $s0, …, $s4 � Load values from memory into registers � Store result from register to memory � Compiled MIPS code: � Memory is byte addressed ����������������� � Each address identifies an 8-bit byte ����������������� � Words are aligned in memory ����������������� � Address must be a multiple of 4 � MIPS is Big Endian � Most-significant byte at least address of a word � c.f. Little Endian: least-significant byte at least address Chapter 2 — Instructions: Language of the Computer — 7 Chapter 2 — Instructions: Language of the Computer — 8 Memory Operand Example 1 Memory Operand Example 2 � C code: � C code: ��������� !"� � ��"�������� !"� � g in $s1, h in $s2, base address of A in $s3 � h in $s2, base address of A in $s3 � Compiled MIPS code: � Compiled MIPS code: � Index 8 requires offset of 32 � Index 8 requires offset of 32 � 4 bytes per word #$��������������������#%���$%&� #$��������������������#%���$%&� ����������������� �$��������!�������������%&��$%&� ����������������� offset base register Chapter 2 — Instructions: Language of the Computer — 9 Chapter 2 — Instructions: Language of the Computer — 10 Registers vs. Memory Immediate Operands � Registers are faster to access than � Constant data specified in an instruction memory ���������������� � Operating on memory data requires loads � No subtract immediate instruction and stores � Just use a negative constant � More instructions to be executed ����������������� � Compiler must use registers for variables � Design Principle 3: Make the common as much as possible case fast � Only spill to memory for less frequently used � Small constants are common variables � Register optimization is important! � Immediate operand avoids a load instruction Chapter 2 — Instructions: Language of the Computer — 11 Chapter 2 — Instructions: Language of the Computer — 12 Chapter 2 — Instructions: Language of the Computer 2

  3. The University of Adelaide, School of Computer Science 8 March 2012 §2.4 Signed and Unsigned Numbers The Constant Zero Unsigned Binary Integers � MIPS register 0 ($zero) is the constant 0 � Given an n-bit number � Cannot be overwritten n 1 n 2 1 0 x x 2 − x 2 − � x 2 x 2 = + + + + n 1 n 2 1 0 − − � Useful for common operations � Range: 0 to +2 n – 1 � E.g., move between registers � Example ���������������'�&% � 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + … + 1×2 3 + 0×2 2 +1×2 1 +1×2 0 = 0 + … + 8 + 0 + 2 + 1 = 11 10 � Using 32 bits � 0 to +4,294,967,295 Chapter 2 — Instructions: Language of the Computer — 13 Chapter 2 — Instructions: Language of the Computer — 14 2s-Complement Signed Integers 2s-Complement Signed Integers � Bit 31 is sign bit � Given an n-bit number � 1 for negative numbers n 1 n 2 1 0 x x 2 − x 2 − � x 2 x 2 = − + + + + � 0 for non-negative numbers n 1 n 2 1 0 − − � –(–2 n – 1 ) can’t be represented � Range: –2 n – 1 to +2 n – 1 – 1 � Non-negative numbers have the same unsigned � Example and 2s-complement representation � 1111 1111 1111 1111 1111 1111 1111 1100 2 � Some specific numbers = –1×2 31 + 1×2 30 + … + 1×2 2 +0×2 1 +0×2 0 0: 0000 0000 … 0000 � = –2,147,483,648 + 2,147,483,644 = –4 10 � –1: 1111 1111 … 1111 � Using 32 bits � Most-negative: 1000 0000 … 0000 � Most-positive: 0111 1111 … 1111 � –2,147,483,648 to +2,147,483,647 Chapter 2 — Instructions: Language of the Computer — 15 Chapter 2 — Instructions: Language of the Computer — 16 Signed Negation Sign Extension � Representing a number using more bits � Complement and add 1 � Preserve the numeric value � Complement means 1 � 0, 0 � 1 � In MIPS instruction set � ���� : extend immediate value x x 1111...111 1 + = = − 2 � #� , #� : extend loaded byte/halfword x 1 x � ��( , �)� : extend the displacement + = − � Replicate the sign bit to the left � Example: negate +2 � c.f. unsigned values: extend with 0s � +2 = 0000 0000 … 0010 2 � Examples: 8-bit to 16-bit � +2: 0000 0010 => 0000 0000 0000 0010 � –2 = 1111 1111 … 1101 2 + 1 � –2: 1111 1110 => 1111 1111 1111 1110 = 1111 1111 … 1110 2 Chapter 2 — Instructions: Language of the Computer — 17 Chapter 2 — Instructions: Language of the Computer — 18 Chapter 2 — Instructions: Language of the Computer 3

Recommend


More recommend