1 Basics of MIPS ISA Pavel Kryukov 8 November 2014.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
ISA Issues; Performance Considerations. Testing / System Verilog: ECE385.
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
331 W08.1Spring :332:331 Computer Architecture and Assembly Language Spring 2006 Week 8: Datapath Design [Adapted from Dave Patterson’s UCB CS152.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Computer ArchitectureFall 2007 © October 3rd, 2007 Majd F. Sakr CS-447– Computer Architecture.
The Processor 2 Andreas Klappenecker CPSC321 Computer Architecture.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
ECE 4436ECE 5367 ISA I. ECE 4436ECE 5367 CPU = Seconds= Instructions x Cycles x Seconds Time Program Program Instruction Cycle CPU = Seconds= Instructions.
The Processor Data Path & Control Chapter 5 Part 1 - Introduction and Single Clock Cycle Design N. Guydosh 2/29/04.
1 Today  Finish-up procedures/stack  strlen example  Machine language, the binary representation for instructions. —We’ll see how it is designed for.
1 Layers of Computer Science, ISA and uArch Alexander Titov 20 September 2014.
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections
1 CS232: Computer Architecture II Fall 2011 Intel i7 Quad-core.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
Chapter 2-2 Assembly Instructions Number Systems Number Systems Assembly Instructions Assembly Instructions Branch Branch Next Lecture Next Lecture  Addressing.
1 Instruction Set Architecture (ISA) Alexander Titov 10/20/2012.
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
Lec 15Systems Architecture1 Systems Architecture Lecture 15: A Simple Implementation of MIPS Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Lecture 4: MIPS Instruction Set
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture.
Crosscutting Issues: The Rôle of Compilers Architects must be aware of current compiler technology Compiler Architecture.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
MS108 Computer System I Lecture 3 ISA Prof. Xiaoyao Liang 2015/3/13 1.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
June 14, 2016Machine Language and Pointers1 What does this C code do? int foo(char *s) { int L = 0; while (*s++) { ++L; } return L; }
CS 61C: Great Ideas in Computer Architecture MIPS Datapath 1 Instructors: Nicholas Weaver & Vladimir Stojanovic
Computer Architecture Lecture 6.  Our implementation of the MIPS is simplified memory-reference instructions: lw, sw arithmetic-logical instructions:
MIPS Assembly.
Electrical and Computer Engineering University of Cyprus
COMPUTER ARCHITECTURE & OPERATIONS I
Instruction Set Architecture
Morgan Kaufmann Publishers
Introduction CPU performance factors
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Prof. Sirer CS 316 Cornell University
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
The University of Adelaide, School of Computer Science
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Topic 5: Processor Architecture Implementation Methodology
Rocky K. C. Chang 6 November 2017
Instruction encoding The ISA defines Format = Encoding
Topic 5: Processor Architecture
COMS 361 Computer Organization
Computer Instructions
COMP541 Datapaths I Montek Singh Mar 18, 2010.
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
MIPS Processor.
Presentation transcript:

1 Basics of MIPS ISA Pavel Kryukov 8 November 2014

2 Moscow Institute of Physics and Technology MIPT-MIPS Project Layers of Abstraction in Computes Science (CS) Application Algorithms Programming Language Operating System Instruction Set Architecture Microarchitecture Gates/Register-Transfer Level (RTL) Circuits Physics Topic of this lecture

3 Moscow Institute of Physics and Technology MIPT-MIPS Project What is ISA Instruction Set Architecture (ISA) is a precise definition of computer instructions, features and mechanism (procedures, interrupt/exception handler, etc.) and also some structures (registers, memory, etc.) It can be thought as an agreement between a programmer and an engineer: It’s all programmer needs to program machine. It’s all hardware designer needs to design machine. What a typical ISA defines Data Formats. (Integer, Floating Point, Vector/Packed) Instructions. (Operations, encoding, etc.) Registers and Memory Organization. Interrupts, exceptions, and traps, other features.

4 Moscow Institute of Physics and Technology MIPT-MIPS Project Example of ISA and their uArches: MIPS An example of a RISC processor. Designed for easy programming and implementation. Short and simple, but fast instructions → programs are larger than others, but run faster. The main aim was to take advantages of pipelined execution Pipeline was not specified in ISA, but ISA developers tried to simplify its implementation in uArch. Implementations: The first one is R2000 (1986) Later: R3000A (PlayStation), R4000 (PSP), R5900 (PlayStation 2), etc. Currently it is widely used in embedded systems. One moment MIPS seemed to be overcome Intel IA-32, but it didn’t happen because Intel’s uArch was significantly better and could compensate the drawback of IA-32. One moment MIPS seemed to be overcome Intel IA-32,, but it didn’t happen because Intel’s uArch was significantly better and could compensate the drawback of IA-32.

5 Moscow Institute of Physics and Technology MIPT-MIPS Project MIPS: Register-To-Register, Three Address MIPS is a register-to-register, or load/store, architecture The destination and sources must all be registers Special instructions, which we’ll see soon, are needed to access main memory MIPS uses three-address instructions for data manipulation Each ALU instruction contains a destination and two sources For example, an addition instruction (a = b + c) has the form: add a, b, c operandsoperation destination source 1 source 2

MIPS Registers 6

7 Moscow Institute of Physics and Technology MIPT-MIPS Project MIPS Register File MIPS processors have 32 registers, each of which holds a 32-bit value Register addresses are 5 bits long The data inputs and outputs are 32-bits wide More registers might seem better, but there is a limit to the goodness The more register the larger decoders, multiplexers, etc. → larger circuits delays Instruction length is affected, as need more space to encode register numbers

8 Moscow Institute of Physics and Technology MIPT-MIPS Project MIPS Register Names MIPS register names begin with a $. There are two naming conventions: By number: $0 $1 $2 … $31 By (mostly) two-character names, such as: $a0-$a3 $s0-$s7 $t0-$t9 $sp $ra NumberName $0$zero $1$at $2, $3$v0, $v1 $4 - $7$a0 - $a3 $8 - $15$t0 - $t7 $15 - $23$s0 - $s7 $24, $25$t8, $t9 $26, $27$k0, $k1 $28$gp $29$sp $30$fp $31$ra Detailed description of each register can be seen by this linkthis link Why so many different registers? Not all of them are general purpose registers (GPR) There are a lot of special purposes: procedure mechanism, exception/interrupt handling, etc. In our project mostly GRPs are used: $t and $s

MIPS Instructions 9

10 Moscow Institute of Physics and Technology MIPT-MIPS Project R-type Format Register-to-register (three register operands) arithmetic instructions use the R-type format: This format includes six different fields: op is an operation code that selects a specific action (also defines the format) rs and rt are the first and second source registers rd is the destination register shamt is only used for shift instructions func is used together with op to select an arithmetic instruction Example: oprsrtrdshamtfunct 6 bits5 bits 6 bits | | | | | opcodersrtrdshamtfunct add$s1$s2 $t0 signed

11 Moscow Institute of Physics and Technology MIPT-MIPS Project Immediate Operands R-type instructions take data from registers. How does it occur there? From the memory (on the next foils) From immediate MIPS allows to specify a immediate value (signed constant), for the second source instead of a register, i.e. instead of rt For example: addi $t0, $t1, 4 # $t0 = $t1 + 4 rt field is too small to preset real constants 5 bits → values from [-16; 15] Cannot use R-type format to encode such instructions → need a new format

12 Moscow Institute of Physics and Technology MIPT-MIPS Project I-type Format for ALU Instructions ALU instructions with immediate (two register operands) use the I-type format: For uniformity, op, rs and rt are in the same positions as in the R-type format This format includes four different fields: rs is a source register (first operand) rt is a destination register imm is a signed value of the second operand The immediate can range from -32,768 to +32,767 But that’s not always enough → need to write to a register by halves oprsrtimm 6 bits5 bits 16 bits

13 Moscow Institute of Physics and Technology MIPT-MIPS Project I-type Format for Loads/Stores for( int i=0; i < L; i++) { int v1 = array[i].v1; int v2 = array[i].v2; … } oprsrtoffset 6 bits5 bits 16 bits I-type format is also used for memory operations (load/store) as they are usually have constant memory displacement: This format includes four different fields: rs is a source register, the base of an address for loads and stores rt is a source register for stores, but a destination register for loads offset is used as an increment to the base to get the address Examples lw $t1, 0x0004($t2) # Read 4B into $t1 from Mem[ Reg[ $t2] ] sw $t1, 0x0004($t2) # Write 4B from $t1 into Mem[ Reg[ $t2] ]

14 Moscow Institute of Physics and Technology MIPT-MIPS Project I-type format is also used for branches. The target address is calculated as the end address of the branch (PC+4) plus the displacement encoded in the instruction This format includes four different fields: rs and rt are the first and second source registers offset is specified in terms of words instead of bytes: target PC = ( PC + 4) + offset << 2 The branch condition is calculated depending on opcode and source values: For example, beq write the target address into PC only if its source operands are equal I-type Format for Branches beq $t1, $t2, L add $s1, $s0, $0 add $t3, $t1, $t1 L: add $v1, $v0, $v0 oprsrtoffset in words 6 bits5 bits 16 bits

15 Moscow Institute of Physics and Technology MIPT-MIPS Project J-type format J-type format is used for instructions that do not access any specified register. They are usually unconditional branches (jumps) Unlike I-type branches, the offset is not added, but change the least bits of PC: target PC = ( PC & 0xf ) | offset << 2 opoffset in words 6 bits26 bits

16 Moscow Institute of Physics and Technology MIPT-MIPS Project MIPS ALU with Register File

A2: MIPS Disassembler 17

18 Moscow Institute of Physics and Technology MIPT-MIPS Project What is disassembler Although formatted 4-bytes opcodes are compact and fully readable by processor, for programmer it is very complicated. People use assembler language — a language with translates understandable and standardized statement. Every statement can be converted to 4-byte instruction — it is called assembling. Vice versa, every 4-byte instruction can be converted to statement of assembler language — disassembling. Disassembling is useful during development of any simulator, architectual or micro-architectual, functional or performance.

19 Moscow Institute of Physics and Technology MIPT-MIPS Project Static and runtime disassembler We are going to start from static disassembler It can be simply reused to make a runtime disassembler

20 Moscow Institute of Physics and Technology MIPT-MIPS Project C-style union To handle with complicated bit structures, C-style unions can be used A union is a special data type available in C that enables you to store different data types in the same memory location union { struct { unsigned imm:16; unsigned t:5; unsigned s:5; unsigned opcode:6; } asI; struct { //... } asR; struct { //... } asJ; uint32 raw; } bytes;

21 Moscow Institute of Physics and Technology MIPT-MIPS Project ISA table To store ISA information we suggest you to use static array. There is example of this array below. struct ISAEntry { const char* name; uint8 opcode; uint8 func; FuncInstr::FormatType format; FuncInstr::Type type; //... }; static const ISAEntry[] isaTable; const FuncInstr::ISAEntry[] FuncInstr::isaTable = { // name opcode func format type { "add ", 0x0, 0x20, FuncInstr::FORMAT_R, FuncInstr::ADD /*...*/ }, // more instructions... }; Because there are not so many instructions, you may find instruction via iterative search

22 Moscow Institute of Physics and Technology MIPT-MIPS Project More information and deadlines Disassembled program will be loaded from memory model (A1) You have to check-out to your new branch our version of A1 even if your implementation is fully correct Link with additional useful materials and list of instructions you have to support will be sent to you tomorrow Deadline is 7 Dec On any questions about A2, please contact Pavel Kryukov

23 Moscow Institute of Physics and Technology MIPT-MIPS Project Test announcement The next class (15 Nov) is test The tests will include questions based on the material of the 2­­­−5th lectures2­­­−5th lectures There will be no question on semiconductors, n/p-doping and transistor structure! In addition, there will be questions on C++. Knowledge of 1 and 2 chapters of Schildt manual is welcome

Thank You 24