|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
最近在学mips,共享mips资料
MIPS Assembly Language Programming
Robert Britton
Computer Science Department
California State University, Chico
Chico, California
Contents
CHAPTER 1: The MIPS Architecture............................................................................... 1
1.1 Introduction..........................................................................................................1
1.2 The Datapath Diagram......................................................................................... 1
1.3 Instruction Fetch and Execute.............................................................................. 2
1.4 The MIPS Register File ....................................................................................... 3
1.5 The Arithmetic and Logic Unit (ALU)................................................................ 3
1.6 The Program Counter (PC) .................................................................................. 4
1.7 Memory................................................................................................................5
1.8 The Instruction Register (IR)............................................................................... 5
1.9 The Control Unit.................................................................................................. 5
1.10 Instruction Set ...................................................................................................... 6
1.11 Addressing Modes ............................................................................................... 7
1.12 Summary.............................................................................................................. 8
Exercises ......................................................................................................................... 8
CHAPTER 2: Pseudocode ................................................................................................. 9
2.1 Introduction..........................................................................................................9
2.2 Develop the Algorithm in Pseudocode ................................................................ 9
2.3 Register Usage Convention................................................................................ 12
2.4 The MIPS Instruction Set................................................................................... 12
2.5 Translation of an “IF THEN ELSE” Control Structure..................................... 13
2.6 Translation of a “WHILE” Control Structure.................................................... 14
2.7 Translation of a “FOR LOOP” Control Structure.............................................. 14
2.8 Translation of Arithmetic Expressions .............................................................. 15
2.9 Translation of a “SWITCH” Control Structure ................................................. 16
2.10 Assembler Directives......................................................................................... 17
2.11 Input and Output ................................................................................................ 18
Exercises ....................................................................................................................... 18
CHAPTER 3: Number Systems....................................................................................... 21
3.1 Introduction........................................................................................................ 21
3.2 Positional Notation............................................................................................. 21
3.3 Converting Binary Numbers to Decimal Numbers............................................ 22
3.4 Detecting if a Binary Number is Odd or Even................................................... 22
3.5 Multiplication by Constants that are a Power of Two ....................................... 23
3.6 The Double and Add Method ............................................................................ 23
3.7 Converting Decimal Numbers to Binary Numbers............................................ 24
3.8 The Two’s Complement Number System.......................................................... 24
3.9 The Two’s Complement Operation ................................................................... 25
3.10 A Shortcut for Finding the Two’s Complement of any Number....................... 25
3.11 Sign Extension ................................................................................................... 26
3.12 Binary Addition ................................................................................................. 26
3.13 Binary Subtraction ............................................................................................. 26
3.14 Overflow Detection............................................................................................ 27
3.15 Hexadecimal Numbers....................................................................................... 27
Exercises ....................................................................................................................... 28
CHAPTER 4: PCSpim The MIPS Simulator................................................................... 31
4.1 Introduction........................................................................................................ 31
4.2 Advantages of a Simulator................................................................................. 31
4.3 The Big Picture .................................................................................................. 32
4.4 Analyzing the Text Segment.............................................................................. 34
4.5 Analyzing the Data Segment ............................................................................. 35
4.6 System I/O ......................................................................................................... 36
4.7 Deficiencies of the System I/O Services............................................................ 36
Exercises ....................................................................................................................... 38
CHAPTER 5: Algorithm Development........................................................................... 39
5.1 Introduction........................................................................................................ 39
5.2 Instructions that Perform Logical Operations.................................................... 39
5.3 Instructions that Perform Shift Operations ........................................................ 41
5.4 Modular Program Design and Documentation .................................................. 42
5.5 A Function to Print Values in Hexadecimal Representation ............................. 47
5.6 A Function to Read Values in Hexadecimal Representation............................. 48
5.7 A Function to Print Decimal Values Right Justified ......................................... 49
5.8 A Function to Read Decimal Values and Detect Errors .................................... 49
Exercises ....................................................................................................................... 50
CHAPTER 6: Function Calls Using the Stack ................................................................ 53
6.1 Introduction........................................................................................................ 53
6.2 The Stack Segment in Memory.......................................................................... 53
6.3 Argument Passing Convention .......................................................................... 53
6.4 Nested Function Calls and Leaf Functions ........................................................ 54
6.5 Local Variables are Allocated Space on the Stack ............................................ 55
6.6 Frame Pointer..................................................................................................... 55
Exercises ....................................................................................................................... 56
CHAPTER 7: Reentrant Functions.................................................................................. 59
7.1 Introduction........................................................................................................ 59
7.2 Rules for Writing Reentrant Code ..................................................................... 59
7.3 Reentrant I/O Functions..................................................................................... 60
7.4 Personal Computers ........................................................................................... 60
7.5 Recursive Functions........................................................................................... 60
Exercises ....................................................................................................................... 61
CHAPTER 8: Exception Processing................................................................................ 63
8.1 Introduction........................................................................................................ 63
8.2 The Trap Handler............................................................................................... 63
Exercises ....................................................................................................................... 65
CHAPTER 9: A Pipelined Implementation..................................................................... 67
9.1 Introduction........................................................................................................ 67
9.2 A Pipelined Datapath ......................................................................................... 68
9.3 PCSpim Option to Simulate a Pipelined Implementation.................................. 69
Exercises ....................................................................................................................... 69
CHAPTER 10: Embedded Processors............................................................................. 71
10.1 Introduction........................................................................................................ 71
10.2 Code Development for Embedded Processors................................................... 71
10.3 Memory Mapped I/O ......................................................................................... 72
10.4 References.......................................................................................................... 72
APPENDIX A: Quick Reference..................................................................................... 73
APPENDIX B: ASCII Codes........................................................................................... 77
APPENDIX C: Integer Instruction Set ............................................................................ 79
APPENDIX D: Macro Instructions ................................................................................. 95
APPENDIX E: A Trap Handler..................................................................................... 100 |
|