3 Data Path Diagram Program Counter (PC) Program Memory Instruction Register ALU Address Control Logic Rs Data In Rdest Rt 4 Data Memory (Register File) The MIPS Instruction Set Used as an example throughout the text book. Stanford MIPS commercialized by MIPS Technologies A discussion of MIPS can be found on Wikipedia Decent share of embedded core market Applications in consumer electronics, network/storage equipment, cameras, printers, Typical of many modern ISAs 3

4 Two Key Principles of Processor Design Instructions are represented as numbers and, as such, are indistinguishable from data. Programs are stored in alterable memory (that can be read or written to) just like data. Stored-program concept - Programs can be shipped as files of binary numbers binary compatibility. - Computers can inherit ready-made software provided they are compatible with an existing Instruction Set Architecture (ISA) leads industry to align around a small number of ISAs. Memory Accounting prg (machine code) C compiler (machine code) Payroll data Source code in C for Acct prg MIPS (RISC) Design Principles Simplicity favors regularity: Fixed size instructions. Small number of instruction formats. Operation code always the first 6 bits in an instruction. Smaller is faster: Limited instruction set. Limited number of registers in register file. Limited number of addressing modes. Make the common case fast: Arithmetic operands taken only from the register file. Allow instructions to contain immediate operands. 4

14 MIPS Assembly Language Program Structure Just plain text file with data declarations, program code (name of file should end in suffix.s to be used with SPIM simulator) Data declaration section followed by program code section Data Declarations Placed in section of program identified with assembler directive.data Declares variable names used in program; storage allocated in main memory (RAM) 14

15 Code Placed in section of text identified with assembler directive.text Contains program code (instructions) Starting point for code execution given label main: Ending point of main code should use exit system call (covered later under System Calls) Comments Anything following # on a line # This stuff would be considered a comment 15

17 Summary MIPS processors have been around since the 1980 s Commercially available and used extensively MIPS uses 32 registers for local storage Data types are standard Each processor defines an instruction set This set is a compromise between programmer convenience and hardware cost; Some instruction sets are the same length, some not. Most processors contains a bank of registers for high-speed storage; Processors are classified as either RISC or CISC. QTSPIM Introduction What is SPIM? a simulator that runs assembly programs for MIPS R2000/R3000 RISC computers What does SPIM do? reads MIPS assembly language files and translates to machine language executes the machine language instructions shows contents of registers and memory works as a debugger (supports break-points and single-stepping) provides basic Operating System (OS)-like services, like simple I/O 17

18 Learning MIPS & SPIM MIPS assembly is a low-level programming language. The best way to learn any programming language is from live code. We will start by going through a few example programs and explaining the key concepts. Further, an examples directory has been created in /wwu/class/cptr280 of several simple, well-documented assembly programs for you to experiment with. Line-by-line syntax can best be learned by picking up what you need from the textbook and on-line tutorials. Start by copying existing programs and modifying them incrementally making sure you understand the behavior at each step. Tip: The best way to understand and remember a construct or keyword is to experiment with it in code, not by reading about it. PCSpim Windows Interface Registers window shows the values of all registers in the MIPS CPU and FPU Messages window shows PCSpim messages Data segment window shows the data loaded into the program s memory and the data of the program s stack Text segment window shows assembly instructions & corresponding machine code Separate console window appears for I/O 18

19 Using SPIM Loading source file Use File -> Open menu Simulation Simulator -> Settings : In the Display section check only the first two items: Save window positions and General registers in hexadecimal In the Execution section check only Allow pseudo instructions Simulator -> Set Value : to load PC with address of first instruction enter Address or Register Name as PC and enter Value as 0x reason: the text area of memory, where programs are stored, starts here Simulator -> Go : run loaded program Click the OK button in the Run Parameters pop-up window if the StartingAddress: value is 0x Simulator -> Break : stop execution Simulator -> Clear Registers and Reinitialize : clean-up before new run Using SPIM Simulator -> Reload : load file again after editing Simulator -> Single Step or Multiple Step : stepping to debug Simulator -> Breakpoints : set breakpoints Notes: Text segment window of SPIM shows assembly and corresponding machine code pseudo-instructions each expand to more than one machine instruction If Load trap file is checked in Simulator -> Settings then text segment shows additional trap-handling code If Delayed Branches is checked in Simulator -> Settings then statementx will execute before control jumps to L1 in following code to avoid this, insert nop before statementx: jal L1 statementx L1: nop 19

24 More SPIM Example Programs In the class examples directory you will find 18 simple well-documented MIPS assembly programs. Run the code in the order below of increasing complexity. 1. add2numbersprog1 2. add2numbersprog2 3. storewords 4. swap2memorywords 5. branchjump 6. systemcalls 7. overflow 8. averageofbytes 9. printloop 10. sumofsquaresprog1 11. sumofsquaresprog2 12. sumofsquaresprog3 13. proccallsprog1 14. proccallsprog1modified 15. proccallsprog2 16. addfirst factorialnonrecursive 18. factorialrecursive Conclusions The code presented so far should get you started in writing your own MIPS assembly. Remember the only way to master the MIPS assembly language in fact, any computer language is to write lots and lots of code. For anyone aspiring to understand modern computer architecture it is extremely important to master MIPS assembly as all modern computers (since the mid-80 s) have been inspired by, if not based fully or partly on the MIPS instruction set architecture. 24

MIPS (SPIM) Assembler Syntax Comments begin with # Everything from # to the end of the line is ignored Identifiers are a sequence of alphanumeric characters, underbars (_), and dots () that do not begin

SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large

Introduction to MIPS Instruction Set Architecture The MIPS used by SPIM is a 32-bit reduced instruction set architecture with 32 integer and 32 floating point registers. Other characteristics are as follows:

Computer Architecture Lecture 2 : Instructions 1 Components of a Computer Hierarchical Layers of Program Code 3 Instruction Set The repertoire of instructions of a computer 2.1 Intr roduction Different

MIPS Instruction ti Set Architecture I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Architecture (1) the attributes of a system as seen by the

Shift and Rotate Instructions Shift and rotate instructions facilitate manipulations of data (that is, modifying part of a 32-bit data word). Such operations might include: Re-arrangement of bytes in a

CPS311 - COMPUTER ORGANIZATION A Brief Introduction to the MIPS Architecture A bit of history The MIPS architecture grows out of an early 1980's research project at Stanford University. In 1984, MIPS computer

MIPS Branch and Jump Instructions Cptr280 Dr Curtis Nelson Review of the Machine Cycle When a program is executing, its instructions are located in main memory. The address of an instruction is the address

Assembly Language Programming Remember the programmer shown in our first lecture? Originally, computers were programmed manually. After a while, scientists began to consider ways to accelerate and facilitate

Programming with QtSpim: A User s Manual John McCranie November 15, 2013 1 1 Introduction to SPIM Spim is a self-contained simulator that runs MIPS32 programs. It utilizes the instruction set originally

CO20-320241 Computer Architecture and Programming Languages CAPL Lecture 13 & 14 Dr. Kinga Lipskoch Fall 2017 Frame Pointer (1) The stack is also used to store variables that are local to function, but

Instructions (354 Review) Forecast Instructions are the words of a computer Instruction set architecture (ISA) is its vocabulary With a few other things, this defines the interface of computers But implementations

COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

Instruction Set Architecture (ISA)... the attributes of a [computing] system as seen by the programmer, i.e. the conceptual structure and functional behavior, as distinct from the organization of the data

EE 352 Unit 3 MIPS ISA Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system Instruction set is the vocabulary the HW can understand and the SW is composed

Supplement for MIPS (Section 44 of the textbook) Section 44 does a good job emphasizing that MARIE is a toy architecture that lacks key feature of real-world computer architectures Most noticable, MARIE

ISA: The Hardware Software Interface Instruction Set Architecture (ISA) is where software meets hardware In embedded systems, this boundary is often flexible Understanding of ISA design is therefore important

1 EE 109 Unit 8 MIPS Instruction Set 2 Architecting a vocabulary for the HW INSTRUCTION SET OVERVIEW 3 Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system

MIPS Stacks and Subroutine Calls Cptr280 Dr Curtis Nelson MIPS Procedure Calls - Review When making a procedure or function call, it is necessary to: Place parameters you wish to pass where they can be

Control Implementation Alternatives Control may be designed using one of several initial representations. The choice of sequence control, and how logic is represented, can then be determined independently;

CSE 30321 Lecture 07-08 In Class Example Handout Part A: J-Type Example: If you look in your book at the syntax for j (an unconditional jump instruction), you see something like: e.g. j addr would seemingly

CS/COE0447: Computer Organization and Assembly Language Datapath and Control Sangyeun Cho Dept. of Computer Science A simple MIPS We will design a simple MIPS processor that supports a small instruction

ECE 312: Semester Project MIPS PROJECT INSTRUCTION SET FORMAT This is a description of the required MIPS instruction set, their meanings, syntax, semantics, bit encodings. The syntax given for each instruction

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences CS61c Summer 2001 Woojin Yu Midterm Exam This is a closed-book exam. No calculators

The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?

Chapter 4 The Processor Part I Introduction CPU performance factors Instruction count Determined by ISA and compiler CPI and Cycle time Determined by CPU hardware We will examine two MIPS implementations