--- created_at: '2014-04-19T18:40:26.000Z' title: Introduction to MIPS assembly language (2007) url: http://chortle.ccsu.edu/AssemblyTutorial/index.html author: jwdunne points: 65 story_text: '' comment_text: num_comments: 49 story_id: story_title: story_url: parent_id: created_at_i: 1397932826 _tags: - story - author_jwdunne - story_7614260 objectID: '7614260' year: 2007 --- [Source](http://chortle.ccsu.edu/AssemblyTutorial/index.html "Permalink to Programmed Introduction to MIPS Assembly Language") # Programmed Introduction to MIPS Assembly Language ![Programmed Introduction to MIPS Assembly Language][1] #### Central Connecticut State University #### QtSpim Edition, August 2015 | ----- | | This is a course in assembly language programming of the MIPS processor. It emphasizes the topics needed for study of computer architecture: bits, bit patterns, operations on bit patterns, and how bit patterns represent instructions and data. This course is equivalent to a semester-long junior college or university course (except, perhaps, for the emphasis on bit patterns). The emphasis of the course is on understanding how computers work. This will provide a basis for further study of computer architecture and computer software. The MIPS processor, the subject of this course, has a well designed architecture and is particularly fruitful to study. However, the goal of the course is not to turn you into a MIPS programmer, but to give you an understanding of all computer systems. The only equipment you need for this course is a PC. The only software you need is the SPIM simulator of the MIPS32 processor and a text editor. The simulator is available by free download (see appendix A). Example programs are presented using an MS Windows operating system. However, you can use any platform that runs SPIM. (There are many). | Assembly Language is normally taken the semester after a course in a high level programming language (such as Java or C). This course assumes that you have this background although no specific programming language is required. Read the pages of this course _actively_. Think about and answer the question at the bottom of each page. (This style of tutorial is called _programmed learning_. It is very effective for technical material). Most questions call for just a little thought. Some call for pencil and paper. Keep a pencil and a scrap of paper next to your keyboard. Each chapter is about 15 pages long. Spend several minutes per page. You can read each chapter in about 30 minutes. However, for maximum benefit, you should run some of the example programs, write some programs of your own, and then think about your results. This may take several hours. | ## Part 1: Prelude to Assembly Language Assembly language: what it is, why it is studied, and where it is used. * [ Chapter 1][2] — Computer Architecture and Assembly Language.   [Quiz][3] * [ Chapter 2][4] — Analog and Binary Signals.   [Quiz][5] * [ Chapter 3][6] — Bits and Bit Patterns.   [Quiz][7] * [ Chapter 4][8] — Computer Organization.   [Quiz][9] ## Part 2: Data Representation Data: characters and integers. The _binary addition algorithm_. * [ Chapter 5][10] — Characters.   [Quiz][11] * [ Chapter 6][12] — Number Representation.   [Quiz][13] * [ Chapter 7][14] — Binary and Hex Representation.   [Quiz][15]   [Flash Cards][16] * [ Chapter 8][17] — Binary Addition and Two's Complement Representation.   [Quiz][18] ## Part 3: Running SPIM; Bitwise Logic Running SPIM. MIPS programming. Bitwise logic operations. * [ Chapter   9][19] — A Simple SPIM Program.   [Quiz][20] * [ Chapter 10][21] — MIPS Programming Model.   [Quiz][22] * [ Chapter 11][23] — Bitwise Logic with Immediate Operands.   [Quiz][24] * [ Chapter 12][25] — Shift Instructions and Logic Instructions.   [Quiz][26]   [Programs][27] ## Part 4: Integer Arithmetic and Memory Access Integer arithmetic. Moving data to and from memory. * [ Chapter 13][28] — Integer Addition and Subtraction Instructions.   [Quiz][29]   [Programs][30] * [ Chapter 14][31] — Integer Multiplication, Division, and Arithmetic Shift.   [Quiz][32]   [Programs][33] * [ Chapter 15][34] — Memory Access**:** Loading and Storing Registers.   [Quiz][35]   [Programs][36] * [ Chapter 16][37] — More Memory Access: Bytes and Halfwords.   [Quiz][38]   [Programs][39] ## Part 5: Branches, Decisions, and Loops Program flow**:** branch, jump, and set instructions; loops, and decisions. * [ Chapter 17][40] — Jump and Branch Instructions.   [Quiz][41]   [Programs][42] * [ Chapter 18][43] — Set Instructions and more Branch Instructions.   [Quiz][44]   [Programs][45] * [ Chapter 19][46] — Structured Programming.   [Quiz][47]   [Programs][48] * [ Chapter 20][49] — Programming Examples.   [Quiz][50]   [Programs][51] ## Part 6: Extended Assembly Language The assembler extends bare machine language. Registers have mnemonic names. _Pseudoinstructions_ extend the bare hardware. * [ Chapter 21][52] — The Extended Assembler.   [Quiz][53]   [Programs][54] * [ Chapter 22][55] — The SPIM Exception Handler.   [Quiz][56]   [Programs][57] * [ Chapter 23][58] — Instructions for Bitwise Logic and Math.   [Quiz][59]   [Programs][60] * [ Chapter 24][61] — Branch Instructions, Set Instructions, and Indexed Addressing.   [Quiz][62]   [Programs][63] ## Part 7: The Stack and Subroutine Linkage Programs are divided into sections called subroutines. At run time, the stack is used to save and to restore a subroutine's values. * [ Chapter 25 ][64] — The Run-time Stack.   [Quiz][65]   [Programs][66] * [ Chapter 26][67] — Simple Subroutine Linkage.   [Quiz][68]   [Programs][69] * [ Chapter 27 ][70] — Stack-based Linkage Convention.   [Quiz][71]   [Programs][72] * [ Chapter 28 ][73] — Frame-based Linkage Convention, Variables, and Recursion.   [Quiz][74]   [Programs][75] ## Part 8: Floating Point Data Bit patterns are used to represent floating point numbers. More machine instructions are used to do floating point arithmetic. * [ Chapter 29 ][76] — Binary Fractions.   [QuizA  ][77]   [QuizB  ][78] * [ Chapter 30 ][79] — IEEE 754 Floating Point.   [Quiz][80] * [ Chapter 31][81] — Floating Point Arithmetic on MIPS.   [Quiz][82]   [Programs][83] * [ Chapter 32 ][84] — Floating Point Comparison Instructions.   [Quiz][85]   [Programs][86] ## Part 9: Data Structures in Assembly Language * [ Chapter 33][87] — Dynamic Memory Allocation.   [Quiz][88]   [Programs][89] * [ Chapter 34][90] — Data Structures.   [Quiz][91]   [Programs][92] * [ Chapter 35][93] — Linked Lists.   [Quiz][94]   [Programs][95] * [ Chapter 36][96] — Objects.   [Quiz][97]   [Programs][98] ## Appendices * [ Appendix A][99] — Downloading and Installing SPIM. * [ Appendix B][100] — Register Use Chart * [ Appendix C][101] — MIPS Assembly Instructions * [ Appendix E ][102] — Binary Addition Calculator (Applet) * [ Appendix F ][103] — ASCII Chart * [ Appendix G ][104] — SPIM Exception Handler Services * [ Appendix H ][105] — Decimal Representation to Binary Conversion (Discussion) * [ Appendix I ][106]   — Decimal to Binary Converter (Applet) ## Index * [Index][107] * * * ![Click here][108][ Main Tutorial Menu ][109] ![Creative Commons License][110] _Programmed Introduction to MIPS Assembly Language_ by Bradley Kjell is licensed under a [Creative Commons Attribution-NonCommercial 4.0 International License][111]. [1]: http://chortle.ccsu.edu/title.gif [2]: http://chortle.ccsu.edu/Chapter-01/ass01_1.html [3]: http://chortle.ccsu.edu/Chapter-01/ass01quiz.html [4]: http://chortle.ccsu.edu/Chapter-02/ass02_1.html [5]: http://chortle.ccsu.edu/Chapter-02/ass02quiz.html [6]: http://chortle.ccsu.edu/Chapter-03/ass03_1.html [7]: http://chortle.ccsu.edu/Chapter-03/ass03quiz.html [8]: http://chortle.ccsu.edu/Chapter-04/ass04_1.html [9]: http://chortle.ccsu.edu/Chapter-04/ass04quiz.html [10]: http://chortle.ccsu.edu/Chapter-05/ass05_1.html [11]: http://chortle.ccsu.edu/Chapter-05/ass05quiz.html [12]: http://chortle.ccsu.edu/Chapter-06/ass06_1.html [13]: http://chortle.ccsu.edu/Chapter-06/ass06quiz.html [14]: http://chortle.ccsu.edu/Chapter-07/ass07_1.html [15]: http://chortle.ccsu.edu/Chapter-07/ass07quiz.html [16]: http://chortle.ccsu.edu/Chapter-07/assFlash07.html [17]: http://chortle.ccsu.edu/Chapter-08/ass08_1.html [18]: http://chortle.ccsu.edu/Chapter-08/ass08quiz.html [19]: http://chortle.ccsu.edu/Chapter-09/ass09_1.html [20]: http://chortle.ccsu.edu/Chapter-09/ass09quiz.html [21]: http://chortle.ccsu.edu/Chapter-10/ass10_1.html [22]: http://chortle.ccsu.edu/Chapter-10/ass10quiz.html [23]: http://chortle.ccsu.edu/Chapter-11/ass11_1.html [24]: http://chortle.ccsu.edu/Chapter-11/ass11quiz.html [25]: http://chortle.ccsu.edu/Chapter-12/ass12_1.html [26]: http://chortle.ccsu.edu/Chapter-12/ass12quiz.html [27]: http://chortle.ccsu.edu/Chapter-12/ass12programs.html [28]: http://chortle.ccsu.edu/Chapter-13/ass13_1.html [29]: http://chortle.ccsu.edu/Chapter-13/ass13quiz.html [30]: http://chortle.ccsu.edu/Chapter-13/ass13programs.html [31]: http://chortle.ccsu.edu/Chapter-14/ass14_1.html [32]: http://chortle.ccsu.edu/Chapter-14/ass14quiz.html [33]: http://chortle.ccsu.edu/Chapter-14/ass14programs.html [34]: http://chortle.ccsu.edu/Chapter-15/ass15_1.html [35]: http://chortle.ccsu.edu/Chapter-15/ass15quiz.html [36]: http://chortle.ccsu.edu/Chapter-15/ass15programs.html [37]: http://chortle.ccsu.edu/Chapter-16/ass16_1.html [38]: http://chortle.ccsu.edu/Chapter-16/ass16quiz.html [39]: http://chortle.ccsu.edu/Chapter-16/ass16programs.html [40]: http://chortle.ccsu.edu/Chapter-17/ass17_1.html [41]: http://chortle.ccsu.edu/Chapter-17/ass17quiz.html [42]: http://chortle.ccsu.edu/Chapter-17/ass17programs.html [43]: http://chortle.ccsu.edu/Chapter-18/ass18_1.html [44]: http://chortle.ccsu.edu/Chapter-18/ass18quiz.html [45]: http://chortle.ccsu.edu/Chapter-18/ass18programs.html [46]: http://chortle.ccsu.edu/Chapter-19/ass19_1.html [47]: http://chortle.ccsu.edu/Chapter-19/ass19quiz.html [48]: http://chortle.ccsu.edu/Chapter-19/ass19programs.html [49]: http://chortle.ccsu.edu/Chapter-20/ass20_1.html [50]: http://chortle.ccsu.edu/Chapter-20/ass20quiz.html [51]: http://chortle.ccsu.edu/Chapter-20/ass20programs.html [52]: http://chortle.ccsu.edu/Chapter-21/ass21_1.html [53]: http://chortle.ccsu.edu/Chapter-21/ass21quiz.html [54]: http://chortle.ccsu.edu/Chapter-21/ass21programs.html [55]: http://chortle.ccsu.edu/Chapter-22/ass22_1.html [56]: http://chortle.ccsu.edu/Chapter-22/ass22quiz.html [57]: http://chortle.ccsu.edu/Chapter-22/ass22programs.html [58]: http://chortle.ccsu.edu/Chapter-23/ass23_1.html [59]: http://chortle.ccsu.edu/Chapter-23/ass23quiz.html [60]: http://chortle.ccsu.edu/Chapter-23/ass23programs.html [61]: http://chortle.ccsu.edu/Chapter-24/ass24_1.html [62]: http://chortle.ccsu.edu/Chapter-24/ass24quiz.html [63]: http://chortle.ccsu.edu/Chapter-24/ass24programs.html [64]: http://chortle.ccsu.edu/Chapter-25/ass25_1.html [65]: http://chortle.ccsu.edu/Chapter-25/ass25quiz.html [66]: http://chortle.ccsu.edu/Chapter-25/ass25programs.html [67]: http://chortle.ccsu.edu/Chapter-26/ass26_1.html [68]: http://chortle.ccsu.edu/Chapter-26/ass26quiz.html [69]: http://chortle.ccsu.edu/Chapter-26/ass26programs.html [70]: http://chortle.ccsu.edu/Chapter-27/ass27_1.html [71]: http://chortle.ccsu.edu/Chapter-27/ass27quiz.html [72]: http://chortle.ccsu.edu/Chapter-27/ass27programs.html [73]: http://chortle.ccsu.edu/Chapter-28/ass28_1.html [74]: http://chortle.ccsu.edu/Chapter-28/ass28quiz.html [75]: http://chortle.ccsu.edu/Chapter-28/ass28programs.html [76]: http://chortle.ccsu.edu/Chapter-29/ass29_1.html [77]: http://chortle.ccsu.edu/Chapter-29/ass29quiz.html [78]: http://chortle.ccsu.edu/Chapter-29/ass29quizB.html [79]: http://chortle.ccsu.edu/Chapter-30/ass30_1.html [80]: http://chortle.ccsu.edu/Chapter-30/ass30quiz.html [81]: http://chortle.ccsu.edu/Chapter-31/ass31_1.html [82]: http://chortle.ccsu.edu/Chapter-31/ass31quiz.html [83]: http://chortle.ccsu.edu/Chapter-31/ass31programs.html [84]: http://chortle.ccsu.edu/Chapter-32/ass32_1.html [85]: http://chortle.ccsu.edu/Chapter-32/ass32quiz.html [86]: http://chortle.ccsu.edu/Chapter-32/ass32programs.html [87]: http://chortle.ccsu.edu/Chapter-33/ass33_1.html [88]: http://chortle.ccsu.edu/Chapter-33/ass33quiz.html [89]: http://chortle.ccsu.edu/Chapter-33/ass33programs.html [90]: http://chortle.ccsu.edu/Chapter-34/ass34_1.html [91]: http://chortle.ccsu.edu/Chapter-34/ass34quiz.html [92]: http://chortle.ccsu.edu/Chapter-34/ass34programs.html [93]: http://chortle.ccsu.edu/Chapter-35/ass35_1.html [94]: http://chortle.ccsu.edu/Chapter-35/ass35quiz.html [95]: http://chortle.ccsu.edu/Chapter-35/ass35programs.html [96]: http://chortle.ccsu.edu/Chapter-36/ass36_1.html [97]: http://chortle.ccsu.edu/Chapter-36/ass36quiz.html [98]: http://chortle.ccsu.edu/Chapter-36/ass36programs.html [99]: http://chortle.ccsu.edu/zAppendixA/appA_1.html [100]: http://chortle.ccsu.edu/zAppendixB/registerUseChart.html [101]: http://chortle.ccsu.edu/zAppendixC/basicInstructions.html [102]: http://chortle.ccsu.edu/zAppendixE/binaryAdd.html [103]: http://chortle.ccsu.edu/zAppendixF/ascii.html [104]: http://chortle.ccsu.edu/zAppendixG/SPIMtraps.html [105]: http://chortle.ccsu.edu/zAppendixH/appH_1.html [106]: http://chortle.ccsu.edu/zAppendixI/converter.html [107]: http://chortle.ccsu.edu/subjectIndex.html [108]: http://chortle.ccsu.edu/contents.gif [109]: http://chortle.ccsu.edu/default.htm [110]: https://i.creativecommons.org/l/by-nc/4.0/88x31.png [111]: http://creativecommons.org/licenses/by-nc/4.0/