
Programmed Introduction to MIPS Assembly Language Bradley Kjell, Central Connecticut State University Revised Draft, June 2002 This is a course in assembly language Assembly Language is normally taken the programming of the MIPS processor. It semester after a course in a high level emphasizes the topics needed for study of programming language (such as Java or C). This computer architecture: bits, bit patterns, course assumes that you have this background, operations on bit patterns, and how bit patterns although no specific programming language is represent instructions and data. This course is required. equivalent to a semester-long junior college or university course (except, perhaps, for the Read the pages of this course actively. Think emphasis on bit patterns). about and answer the question at the bottom of each page. (This style of tutorial is called The only equipment you need for this course is a programmed learning. It is very effective for PC. The only software you need is the SPIM technical material). Most questions call for just a simulator of the MIPS R2000 processor, and a little thought. Some call for pencil and paper. text editor. The simulator is available by free Keep a pencil and a scrap of paper next to your download (see appendix A). Example programs keyboard. Each chapter is about 15 pages long. are presented using an MS Windows operating Spend several minutes per page. You can read system. However, you can use any platform that each chapter in about 30 minutes. runs SPIM. (There are many). Works best with IE 5.0 at 800 by 600 Part 1: Prelude to Assembly Language Assembly language: what it is, why it is studied, and where it is used. ● Chapter 1 — Computer Architecture and Assembly Language. ● Chapter 2 — Analog and Binary Signals. ● Chapter 3 — Bits and Bit Patterns. http://chortle.ccsu.edu/AssemblyTutorial/tutorialContents.html (1 of 4) [7/8/2545 18:08:56] Programmed Introduction to MIPS Assembly Language ● Chapter 4 — Computer Organization. Part 2: Data Representation Data: characters and integers. The binary addition algorithm. ● Chapter 5 — Characters. ● Chapter 6 — Number Representation ● Chapter 7 — Binary and Hex Representation. Flash Cards ● Chapter 8 — Binary Addition and Two's Complement Representation. Part 3: Running SPIM; Bitwise Logic Running SPIM. MIPS programming. Bitwise logic operations. ● Chapter 9 — A Simple SPIM Program. ● Chapter 10 — MIPS Programming Model ● Chapter 11 — Bitwise Logic with Immediate Operands ● Chapter 12 — Shift Instructions and Logic Instructions Part 4: Integer Arithmetic and Memory Access Integer arithmetic. Moving data to and from memory. ● Chapter 13 — Integer Addition and Subtract Instructions ● Chapter 14 — Integer Multiplication, Division, and Arithmetic Shift ● Chapter 15 — Memory Access: Loading and Storing Registers ● Chapter 16 — More Memory Access: Bytes and Halfwords Part 5: Branches, Decisions, and Loops Program flow: branch, jump, and set instructions; loops, and decisions. ● Chapter 17 — Jump and Branch Instructions http://chortle.ccsu.edu/AssemblyTutorial/tutorialContents.html (2 of 4) [7/8/2545 18:08:56] Programmed Introduction to MIPS Assembly Language ● Chapter 18 — Set Instructions and more Branch Instructions ● Chapter 19 — Structured Programming ● Chapter 20 — Loop and Branch Examples Part 6: Extended Assembly Language The assembler extends bare machine language. Registers have mnemonic names. Pseudoinstructions extend the bare hardware. ● Chapter 21 — Pseudoinstructions and the Pseudocomputer ● Chapter 22 — The SPIM Trap Handler ● Chapter 23 — Instructions for Bitwise Logic and Math ● Chapter 24 — Branch Instructions, Set Instructions, and Indexed Addressing Part 7: The Stack and Subroutine Linkage ● Chapter 25 — The Run-time Stack ● Chapter 26 — Simple Subroutine Linkage ● Chapter 27 — Stack-based Calling Convention ● Chapter 28 — Frame-based Calling Convention, Variables, and Recursion Part 8: Floating Point Data ● Chapter 29 — Binary Fractions ● Chapter 30 — IEEE 754 Floating Point ● Chapter 31 — Floating Point Arithmetic on MIPS ● Chapter 32 — Floating Point Comparison Instructions Part 9: Data Structures in Assembly Language. ● Chapter 33 — Future Work. ● Chapter 34 — Future Work. ● Chapter 35 — Future Work. ● Chapter 36 — Future Work. http://chortle.ccsu.edu/AssemblyTutorial/tutorialContents.html (3 of 4) [7/8/2545 18:08:56] Programmed Introduction to MIPS Assembly Language Appendices ● Appendix A — Downloading and Installing SPIM ● Appendix B — Register Use Chart ● Appendix C — MIPS Assembly Instructions ● Appendix D — MIPS Machine Language Format ● Appendix E — Binary Addition Calculator (Java applet) ● Appendix F — ASCII Chart ● Appendix G — SPIM Trap Handler Services Index ● Index Main Tutorial Menu http://chortle.ccsu.edu/AssemblyTutorial/tutorialContents.html (4 of 4) [7/8/2545 18:08:56] CHAPTER 1 — INTRODUCTION created: 06/25/96; 2nd edition: 03/17/01 CHAPTER 1 — INTRODUCTION This is a tutorial in assembly language for the MIPS R2000 processor chip using the SPIM simulator. Assembly language is used to write programs in terms of the basic operations of a processor. The architecture of a computer is a logical description of its components and its basic operations. In "pure" assembly language the architecture of the processor chip is clearly visible: one assembly language statement corresponds to one basic operation of the processor. With assembly language the programmer is clearly aware of the processor that will run the program. "Pure" assembly language is rare. Usually, for programmer convenience, assembly language is extended with statements that correspond to several basic machine operations. MIPS assembly language does this, but the processor chip is still visible. Programs in high level languages such as C or Pascal are (mostly) independent of the processor they run on. The processor is not visible in the language. This chapter starts out a tour of assembly language. Chapter Topics: ● The Basic Computer Cycle. ● Machine Instructions. ● Machine Language. ● Assembly Language. ● Language Translation. ● Emulation. ● Object Modules and Load Modules. ● Separate Assembly. QUESTION 1: Do all processor chips have the same architecture? http://chortle.ccsu.edu/AssemblyTutorial/Chapter-01/ass01_1.html [7/8/2545 18:09:03] Different Processor Architectures Do all processor chips have the same architecture? A good answer might be: No. Each family of processor chip (MIPS, PIC, SPARC, Alpha, Motorola, Intel, et al.) has its own architecture. Different Processor Architectures The architecture of a computer is a description of its components and its operations. Each processor family has its own architecture. Assembly language is a programming view of the architecture of a processor. So each type of processor has its own assembly language. When you study an assembly language, you study the architecture of a particular processor. The study of any assembly language increases your professional understanding of computers These notes are about the MIPS processor, which is a nice processor to study. The concepts in MIPS assembly are universal. These notes discuss assembly language from a computer science perspective. They explain what is going on in a computer system at the assembly language level. This is a view that is above the electronic view of computer architecture, but is below the operating systems view of the computer system. Computer scientists understand computers at many levels. They understand how the many levels are built one on top of another. Each of these levels corresponds to one or more courses in a computer science degree program. QUESTION 2: (Rhetorical) Does your understanding of computers depend on which assembly language you study? http://chortle.ccsu.edu/AssemblyTutorial/Chapter-01/ass01_2.html [7/8/2545 18:09:16] Fundamentals A good answer might be: No. Probably a well-designed modern assembly language is best, but any one is OK. Fundamentals The MIPS architecture is modern and well-designed. MIPS chips were designed from the ground up in 1985. The design includes the best ideas of computer architecture. An assembly language program describes exactly what the hardware should do, step by step, in terms of the basic operations of the computer. In a high level programming language like C or Java a programmer is mostly unaware of computer architecture. The same source program can run (after compiling) on any processor family. These notes are about fundamental assembly-level computer architecture. To do this effectively, it is necessary (in my view) to acutally learn the assembly language and details of a particular processor, and to write programs for it. This is somewhat like those experiments you did in high school chemistry. Their goal was to teach you the fundamentals of chemistry, not to teach you how to make test tubes full of colorful water. But without the colorful experiments your understanding of chemistry might remain abstract and vague, and would soon be forgotten. QUESTION 3: At the time of this writing (Spring 2001) tens of thousands of dot.com workers have been laid off. 1. How many of them were making car payments on a Jaguar? 2. How many of them knew assembly language? http://chortle.ccsu.edu/AssemblyTutorial/Chapter-01/ass01_3.html [7/8/2545 18:09:25] Basic Machine Cycle A good answer might be: 1. How many of them were making car payments on a Jaguar? Must Sell! Make Offer! ❍ Many of them. 2. How many of them knew assembly language? ❍ Few of them. Employment is still strong for computer scientists. It is weak for technicial workers. The used car lots of Silicon Valley are full of repossessed Jaguars (according to a recent news story). Basic Machine Cycle http://chortle.ccsu.edu/AssemblyTutorial/Chapter-01/ass01_4.html (1 of 2) [7/8/2545 18:09:41] Basic Machine Cycle Most processors endlessly repeat three basic steps. Each machine cycle results in the execution of one machine instruction. A modern processor performs millions of machine cycles per second. A machine instruction is a pattern of bits that corresponds to a fundamental operation of the processor, such as adding two 32-bit integers together, or testing if a value is zero. The details of the machine cycle differ between processor families.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages726 Page
-
File Size-