Programmed Introduction To MIPS Assembly Language

2y ago
22 Views
4 Downloads
3.12 MB
726 Pages
Last View : 9d ago
Last Download : 3m ago
Upload by : Halle Mcleod
Transcription

Programmed Introduction to MIPS Assembly LanguageBradley Kjell, Central Connecticut State UniversityRevised Draft, June 2002This is a course in assembly languageAssembly Language is normally taken theprogramming of the MIPS processor. Itemphasizes the topics needed for study ofcomputer architecture: bits, bit patterns,operations on bit patterns, and how bit patternsrepresent instructions and data. This course isequivalent to a semester-long junior college oruniversity course (except, perhaps, for theemphasis on bit patterns).semester after a course in a high levelprogramming language (such as Java or C). Thiscourse assumes that you have this background,although no specific programming language isrequired.The only equipment you need for this course is aPC. The only software you need is the SPIMsimulator of the MIPS R2000 processor, and atext editor. The simulator is available by freedownload (see appendix A). Example programsare presented using an MS Windows operatingsystem. However, you can use any platform thatruns SPIM. (There are many).Read the pages of this course actively. Thinkabout and answer the question at the bottom ofeach page. (This style of tutorial is calledprogrammed learning. It is very effective fortechnical material). Most questions call for just alittle thought. Some call for pencil and paper.Keep a pencil and a scrap of paper next to yourkeyboard. Each chapter is about 15 pages long.Spend several minutes per page. You can readeach chapter in about 30 minutes.Works best with IE 5.0 at 800 by 600Part 1: Prelude to Assembly LanguageAssembly 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 tutorialContents.html (1 of 4) [7/8/2545 18:08:56]

Programmed Introduction to MIPS Assembly LanguageChapter 4 — Computer Organization. Part 2: Data RepresentationData characters and integers. The binary addition algorithm.: Chapter 5 — Characters.Chapter 6 — Number RepresentationChapter 7 — Binary and Hex Representation. Flash CardsChapter 8 — Binary Addition and Two's Complement Representation.Part 3: Running SPIM; Bitwise LogicRunning SPIM. MIPS programming. Bitwise logic operations. Chapter 9 — A Simple SPIM Program.Chapter 10 — MIPS Programming ModelChapter 11 — Bitwise Logic with Immediate OperandsChapter 12 — Shift Instructions and Logic InstructionsPart 4: Integer Arithmetic and Memory AccessInteger arithmetic. Moving data to and from memory. Chapter 13 — Integer Addition and Subtract InstructionsChapter 14 — Integer Multiplication, Division, and Arithmetic ShiftChapter 15 — Memory Access: Loading and Storing RegistersChapter 16 — More Memory Access: Bytes and HalfwordsPart 5: Branches, Decisions, and LoopsProgram flow branch, jump, and set instructions; loops, and decisions.: Chapter 17 — Jump and Branch al/tutorialContents.html (2 of 4) [7/8/2545 18:08:56]

Programmed Introduction to MIPS Assembly Language Chapter 18 — Set Instructions and more Branch InstructionsChapter 19 — Structured ProgrammingChapter 20 — Loop and Branch ExamplesPart 6: Extended Assembly LanguageThe assembler extends bare machine language. Registers have mnemonic names. Pseudoinstructionsextend the bare hardware. Chapter 21 — Pseudoinstructions and the PseudocomputerChapter 22 — The SPIM Trap HandlerChapter 23 — Instructions for Bitwise Logic and MathChapter 24 — Branch Instructions, Set Instructions, and Indexed AddressingPart 7: The Stack and Subroutine Linkage Chapter 25 — The Run-time StackChapter 26 — Simple Subroutine LinkageChapter 27 — Stack-based Calling ConventionChapter 28 — Frame-based Calling Convention, Variables, and RecursionPart 8: Floating Point Data Chapter 29 — Binary FractionsChapter 30 — IEEE 754 Floating PointChapter 31 — Floating Point Arithmetic on MIPSChapter 32 — Floating Point Comparison InstructionsPart 9: Data Structures in Assembly Language. Chapter 33 — Future Work.Chapter 34 — Future Work.Chapter 35 — Future Work.Chapter 36 — Future rialContents.html (3 of 4) [7/8/2545 18:08:56]

Programmed Introduction to MIPS Assembly LanguageAppendices Appendix A — Downloading and Installing SPIMAppendix B — Register Use ChartAppendix C — MIPS Assembly InstructionsAppendix D — MIPS Machine Language FormatAppendix E — Binary Addition Calculator (Java applet)Appendix F — ASCII ChartAppendix G — SPIM Trap Handler ServicesIndex IndexMain Tutorial ialContents.html (4 of 4) [7/8/2545 18:08:56]

CHAPTER 1 — INTRODUCTIONcreated: 06/25/96; 2nd edition: 03/17/01CHAPTER 1 — INTRODUCTIONThis is a tutorial in assembly language for the MIPS R2000 processor chip using the SPIMsimulator. Assembly language is used to write programs in terms of the basic operations ofa processor. The architecture of a computer is a logical description of its components andits basic operations. In "pure" assembly language the architecture of the processor chip isclearly visible: one assembly language statement corresponds to one basic operation of theprocessor. With assembly language the programmer is clearly aware of the processor thatwill run the program."Pure" assembly language is rare. Usually, for programmer convenience, assemblylanguage 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 highlevel 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 assemblylanguage.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 ial/Chapter-01/ass01 1.html [7/8/2545 18:09:03]

Different Processor ArchitecturesDo 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.) hasits own architecture.Different Processor ArchitecturesThe architecture of a computer is a description of itscomponents and its operations.Each processor family has its own architecture.Assembly language is a programming view of thearchitecture of a processor. So each type of processorhas its own assembly language.When you study an assembly language, you study thearchitecture of a particular processor. The study of anyassembly language increases your professionalunderstanding of computers These notes are about theMIPS processor, which is a nice processor to study. Theconcepts in MIPS assembly are universal.These notes discuss assembly language from a computer science perspective. Theyexplain what is going on in a computer system at the assembly language level. This is aview that is above the electronic view of computer architecture, but is below the operatingsystems view of the computer system. Computer scientists understand computers at manylevels. They understand how the many levels are built one on top of another. Each of theselevels corresponds to one or more courses in a computer science degree program.QUESTION 2:(Rhetorical) Does your understanding of computers depend on whichassembly language you pter-01/ass01 2.html [7/8/2545 18:09:16]

FundamentalsA good answer might be:No. Probably a well-designed modern assembly language is best, but any one is OK.FundamentalsThe MIPS architecture is modern and well-designed. MIPS chips were designed from theground up in 1985. The design includes the best ideas of computer architecture.An assembly language program describes exactly what the hardware should do, step bystep, in terms of the basic operations of the computer. In a high level programminglanguage like C or Java a programmer is mostly unaware of computer architecture. Thesame source program can run (after compiling) on any processor family.These notes are about fundamental assembly-level computer architecture. To do thiseffectively, it is necessary (in my view) to acutally learn the assembly language and detailsof a particular processor, and to write programs for it. This is somewhat like thoseexperiments you did in high school chemistry. Their goal was to teach you the fundamentalsof chemistry, not to teach you how to make test tubes full of colorful water. But without thecolorful experiments your understanding of chemistry might remain abstract and vague, andwould soon be forgotten.QUESTION 3:At the time of this writing (Spring 2001) tens of thousands of dot.comworkers have been laid off.1. How many of them were making car payments on a Jaguar?2. How many of them knew assembly Chapter-01/ass01 3.html [7/8/2545 18:09:25]

Basic Machine CycleA good answer might be:1. Howmany ofthem weremakingcarpaymentson aJaguar?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. Theused car lots of Silicon Valley are full of repossessed Jaguars (according to a recentnews story).Basic Machine ter-01/ass01 4.html (1 of 2) [7/8/2545 18:09:41]

Basic Machine CycleMost processors endlessly repeat three basic steps. Each machinecycle results in the execution of one machine instruction. A modernprocessor performs millions of machine cycles per second.A machine instruction is a pattern of bits that corresponds to afundamental operation of the processor, such as adding two 32-bitintegers together, or testing if a value is zero. The details of themachine cycle differ between processor families. The machine cycleof most processor chips looks like the following:Fetch the Instruction. The program counter (PC) is part of theprocessor. It holds the address of the instruction. The machineinstruction is fetched from memory.Increment the Program Counter. The program counter nowholds the address of the next instruction.Execute the Instruction. The operations specified by the current machineinstruction are performed.QUESTION 4:In what order are machine instructions executed by the basic machine pter-01/ass01 4.html (2 of 2) [7/8/2545 18:09:41]

Machine InstructionsIn what order are machine instructions executed by the basic machine cycle?A good answer might be:Sequential order.Machine InstructionsInstructions are normally executed in sequential order. Program loops and branches requiremachine instructions that alter the normal sequence. Operations like "add two integers" and"compute bit-wise or" are operations that a processor does in one machine cycle.A machine instruction is a pattern of bits that directs the processor to perform one machineoperation. Here is the machine instruction that directs the MIPS processor to add two 32-bitregisters together (a register is a part of the processor that can hold a bit pattern).0000 0001 0010 1011 1000 0000 0010 0000The instruction is 32 bits long. Each bit is 0 or 1. When bit patterns are displayed in a bookthey are usually shown in groups of four (as here). Of course, the spaces are a conventionof printing and don't really exist as part of the bit pattern.Some of the bits in the instruction specify the operation (adding two registers), other bitsspecify which two registers to add. A few more bits say were to put the result.QUESTION 5:Inspect the instruction. Is it clear what the bits of the instruction ter-01/ass01 5.html [7/8/2545 18:09:47]

Assembly Language StatementIs it clear what the bits mean?A good answer might be:No.Assembly Language StatementThe layout of a machine instruction is part of the architecture of a processor chip. Withoutknowing the layout you can't tell what the instruction is. Even if you know the layout, it ishard to remember what the patterns mean and hard to write machine instructions "by hand".A statement in pure assembly language corresponds to one machine instruction. Assemblylanguage is much easier to write than machine code. Here is the previous machineinstruction and the assembly language that it corresponds to:machine instructionassembly statement0000 0001 0010 1011 1000 0000 0010 0000add t0, t1, t3The instruction means: add the integers in registers T1 and T2 and put the result in registerT0. To create the machine instruction from the assembly language statement a translationprogram called an assembler is used.Humans find assembly language easier to use than machine language for many reasons. It is hard for humans to keep track of those ones and zeros.By using symbols programmers gain flexibility in describing the computation.Assembly language is a compact notation.Enhanced assembly language includes additional convenience features. It has instructions(called pseudoinstructions) that correspond to several machine instructions. Often amacroprocessor is used to add even more features.QUESTION -01/ass01 6.html (1 of 2) [7/8/2545 18:09:49]

Assembly Language StatementOnce you know assembly language, is it hard to write an assembly Tutorial/Chapter-01/ass01 6.html (2 of 2) [7/8/2545 18:09:49]

Program TranslationA good answer might be:No.Program TranslationThe assembly language statement says the same thing as the machine languageinstruction, but must be translated before it can be used. An assembly language programconsists of assembly language statements, statements that define data, and someadditional information that helps in the translation. Here is a fragment of an assemblylanguage program and its translation into bit patterns.machine instructionsassembly statements0011 0100 0000 0001 0000 0000 0000 10010000 0000 0100 0001 0000 0000 0001 10000000 0000 0000 0000 0100 0000 0001 00100011 0100 0000 0001 0000 0000 0000 10010000 0000 0100 0000 0000 0000 0100 1000ori 1, 0, 9mult 2, 1mflo 8ori 1, 0, 5div 8, 1Years ago, to run a program written in FORTRAN you used a compiler to translate theprogram into assembly language. Then you used an assembler to translate the assemblylanguage into machine language. Finally, you loaded the machine language into thecomputer's memory and executed your program.Modern compilers usually translate a source program directly into machine language whichis contained in a file called an object module (more on this later). But for now let us thinkabout translating FORTRAN into assembly language.FORTRAN is a high level language. It is intended to run on all types of computers,regardless of architecture. FORTRAN statements can be written without knowing thearchitecture of the computer, and can be run on any computer (after translation).QUESTION -01/ass01 7.html (1 of 2) [7/8/2545 18:09:59]

Program TranslationDo you think that languages such as COBOL, C, and Pascal are translatedlike hapter-01/ass01 7.html (2 of 2) [7/8/2545 18:09:59]

Several TranslationsA good answer might be:Yes.Several TranslationsAll programming languages other than machine language must be translated before theycan be executed. A high level language is independent of architecture, but it requires aspecific translator (compiler) for each architecture. The more modern the language, themore distant the source code is from the machine language. FORTRAN is old and is closerto machine language than most languages. Here is a statement in FORTRAN:result 6*alpha betaHere is a translation of that statement into MIPS assembly language:lw t0,alphalw t1,betamul t2, t0,6add t2, t2, t1sw t2,result# copy alpha to register T0# copy beta to register T1# multiply T0 times 6; result in T2# add T2 and T1; result in T2# copy answer to resultHere is a translation of that statement into Digital Equipment Corporation VAX assemblylanguage:MULL3 #6,ALPHA,R5ADDL3 R5,BETA,RESULTQUESTION 8:Is the architecture of the VAX similar to that of ter-01/ass01 8.html [7/8/2545 18:10:24]

Machine LanguageA good answer might be:No. The two machines are very different.Machine LanguageThere is not just one language called "assembly language." Each assembly language is forone type of processor only. MIPS assembly language is only for MIPS processors. The VAXassembly language is only for VAX processors. There is a different assembly language forIBM mainframe computers, and others for Intel-based PCs.Assembly language describes computations in terms of the hardware of a particularprocessor. A high level computer programming language (ideally) describes computations interms of the problem being solved . Since there are many types problems, there are manyhigh level languages, each designed for particular types of problems. For example, objectoriented languages, describe computations in terms of the objects of the problem andoperations with them.It is much easier to program a computer in a high level language than in assemblylanguage, especially when the programming language matches the problem. There willnever be a universal programming language since no one language is best for all problems.QUESTION 9:(Hard thought question:) What type of problem is assembly language bestsuited er-01/ass01 9.html [7/8/2545 18:10:26]

Main Storage(Hard thought question:) What type of problem is assembly language best suited for?A good answer might be:Problems that involve the very computer the program is running on.Main StorageAssembly language does match the problem when the problem is the operation of thecomputer system. Assembly language is used for operating systems, compilers,communications, low-level graphics, and other programs where the architecture of theprocessor must be visible. Often with these program the crucial parts are written inassembly and the rest in a high level language (usually C). The most common use ofassembly language is in programming embedded systems. Here a processor chip is anintegral part of a machine built for a specific purpose. Examples are microwave ovens, VHSplayers, automobile fuel systems, and game consoles. MIPS chips are commonly used inthese (and for this reason more MIPS chips are sold each year than any other processor).Now let us move on to the memory of acomputer system. Eight bits make up abyte. A bit is a single on/off value. Earlycomputers had rows of toggle switcheswhich were used to set the values ofbits in main memory. You couldprogram these computers by enteringthe bits of each machine instruction. Alight above each switch showedwhether it was on or off. Moderncomputers have more convenientmethods for moving bit patterns intomemory.A Beautiful ComputerThe bytes that make up the machine instructions of a program are stored in main memoryand fetched into the processor as needed. Data is also kept in main memory. Keeping bothdata and instructions in main memory is one of the characteristics of a Von Neumannmachine, the name for the basic design of most modern computers.In the MIPS, as in most computers, each byte of main memory has an address. An apter-01/ass01 10.html (1 of 2) [7/8/2545 18:10:48]

Main Storageis a integer that uniquely identifies the byte. The addresses run from 0 up to about fourbillion. However, on the MIPS, user programs and data (such as you will w

Programmed Introduction to MIPS Assembly Language Bradley Kjell, Central Connecticut State University Revised Draft, June 2002 This is a course in assembly language programming of the MIPS processor. It emphasizes the topics needed for study of computer architecture: bits, bit p

Related Documents:

bits, gọi là MIPS-64. MIPS xem xét trong môn học này là MIPS làm việc với các thanh ghi chỉ 32 bit, gọi là MIPS-32. ÞTrong phạm vi môn học này, MIPS dùng chung sẽ hiểu là MIPS-32 Tóm lại, chỉ có 3 loại toán hạng trong một lệnh của MIPS 1. Toán hạng thanh ghi (Register Operands) 2.

Table 1: How 2020 MIPS Final Scores Relate to 2022 MIPS Payment Adjustments Final Score Points MIPS Payment Adjustment 0.00 – 11.25 points Negative (-) MIPS payment adjustment of -9% 11.26 – 44.99 points Negative (-) MIPS payment adjustment, between 0% and -9%, on a linear sliding scale 45.00 points (Performance threshold 45.00 points)

Performance on EEMBC benchmarks aggregate for Consumer, Telecom, Office, Network, based on ARM1136J-S (Freescale i.MX31), ARM1026EJ-S, Tensilica Diamond 570T, T1050 and T1030, MIPS 20K, NECVR5000). MIPS M4K, MIPS 4Ke, MIPS 4Ks, MIPS 24K, ARM 968E-S, ARM 966E-S, ARM926EJ-S, ARM7TDMI-S scaled by ratio of Dhrystone MIPS within architecture family.

ACOs in MIPS receive advantages by being scored under the MIPS APM Scoring Standard, which gives ACOs favorable treatment for their commitment to value-base care. Based on the low bar set for 2019 reporting in MIPS, ACOs should easily avoid penalties under MIPS and will be eligible for MIPS bonuses and exceptional performance bonuses.

Chapter 1: Getting started with mips Remarks This section provides an overview of what mips is, and why a developer might want to use it. It should also mention any large subjects within mips, and link out to the related topics. Since the Documentation for mips is new, you may need to create initial versions of those related topics. Examples

Introduction to MIPS architecture MIPS Assembly Language – Arithmetic: » add, sub, addi, addu, addiu, subu – Data movement : » lw, sw, lbu, sb, lui, ori – Program Control: » Branch, jump, stacks and procedure calls – MIPS programming examples Comp 212 Computer Org & ArchComp 212 Compute

MIPS design: 32 integer registers, each holding 32 bits . Starting on page 51 is an overview of the MIPS assembly commands! MIPS_Green_Sheet.pdf "Cheat sheet" for expert programmers MIPS commands, registers, memory conventions, .

Lung anatomy Breathing Breathing is an automatic and usually subconscious process which is controlled by the brain. The brain will determine how much oxygen we require and how fast we need to breathe in order to supply our vital organs (brain, heart, kidneys, liver, stomach and bowel), as well as our muscles and joints, with enough oxygen to carry out our normal daily activities. In order for .