RISC Concepts, MIPS ISA and the Mini–MIPS project

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

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.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Chapter 2 — Instructions: Language of the Computer — 1 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
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
CS3350B Computer Architecture Winter 2015 Lecture 4
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
CPSC CPSC 3615 Computer Architecture Chapter 3 Instructions and Addressing (Text Book: Chapter 5)
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
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.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Computer Architecture - The Instruction Set The Course’s Goals  To be interesting and fun. An interested student learns more.  To answer questions that.
Lecture 6 Sept 16 Chapter 2 continue MIPS translating c into MIPS – examples MIPS simulator (MARS and SPIM)
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Feb 18, 2009 Lecture 4-1 instruction set architecture (Part II of [Parhami]) MIPS assembly language instructions MIPS assembly programming.
MIPS Instruction Set Advantages
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Lecture 4. Miscellaneous Addressing Mode, Memory Map, Pointer, and ASCII Prof. Taeweon Suh Computer Science Education Korea University ECM534 Advanced.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
CDA 3101 Spring 2016 Introduction to Computer Organization
Computer Architecture Instruction Set Architecture
MIPS Instruction Set Advantages
Computer Architecture Instruction Set Architecture
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
ECE3055 Computer Architecture and Operating Systems MIPS ISA
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Assembly Programming using MIPS R3000 CPU
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
Lecture 5: Procedure Calls
Part II Instruction-Set Architecture
Assembly Programming using MIPS R3000 CPU
7/6/
Presentation transcript:

RISC Concepts, MIPS ISA and the Mini–MIPS project 044262 Logic Design and Intr. to computers Tutorial 7,8 (based on the slides by Hans Holten-Lund)

Machine Instructions The machine can only understand instructions. The instruction set is the vocabulary of the machine. The instruction set architecture (ISA) defines the interface between software and hardware. The ISA allows different machine implementations to run the same software.

MIPS Add/Sub : C program: MIPS instructions: Always three operands: a = b + c; d = a - e; MIPS instructions: add a, b, c sub d, a, e compiler Always three operands: A fixed number of operands makes the hardware simpler.

C compiler example C expression: f = (g + h) – (i + j); C compiler generates these instructions: add $t0, g, h add $t1, i, j sub f, $t0, $t1 Temporary variables: $t0, $t1

Registers Instruction operands are in registers Temporary variables $t0, $t1 are stored in registers. What about f,g,h,i,j ? The MIPS ISA defines “only” 32 registers! Each register 32 bits = word size of the architecture. C integer (int) typically matches word size.

C compiler example with registers C expression: f = (g + h) – (i + j); C compiler register assignment: f,g,h,i,j are assigned to: $s0,$s1,$s2,$s3,$s4 t0,t1: $t0,$t1 Instructions: add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s0, $t0, $t1 The 32 registers have special names (Fig. 3.13)

Register Names Name Reg # Use Preserved on call $zero Constant 0 No Constant 0 No $v0-$v1 2-3 Results and expressions $a0-$a3 4-7 Arguments Yes $t0-$t7 8-15 Temp $s0-$s7 16-23 “saved” $t8-$t9 24-25 $gp 28 Global Pointer $sp 29 Stack Pointer $fp 30 Frame Pointer $ra 31 Return Address

Accessing Memory Arithmetic instructions can only access registers. We need to transfer data between memory and registers. Transferring from memory to register: The Load Word (lw) instruction can move 32 bits of data from a memory address to a register. The Store Word (sw) instruction can move 32 bits of data from a register to a memory address. A 32-bit register can store an address. 2^30 32-bit words can be addressed.

C compiler example with load word C expression: g = h + A[8]; The base address of array A is in register $s3 Offset into array is 8 words or 32 bytes as the MIPS uses byte addressing. One 32-bit word = 4 bytes. Words MUST be 4 byte aligned. C compiler generates a lw-instruction: lw $t0, 32($s3) add $s1, $s2, $t0

32-bit word alignment in byte addressed memory Aligned at 4 (Good): Unaligned at 5 (Bad!): 0 1 2 3 0 1 2 3 4 MSB LSB 4 MSB 8 8 LSB

C compiler example with load/store C expression: A[12] = h + A[8]; C compiler generates lw- and sw-instructions: lw $t0, 32($s3) add $t0, $s2, $t0 sw $t0, 48($s3) Example 2 Variable array index: load from A[i] (i in $s4) add $t1,$s4,$s4 # 2*i add $t1,$t1,$t1 # 4*i add $t1,$t1,$s3 # A + 4*i lw $t0, 0($t1)

Representing Instructions (Arithmetic) C code: temp = (g + h); MIPS assembly instruction: add $t0,$s1,$s2 # add rd,rs,rt : rd=rs+rt Machine language instruction: 000000 10001 10010 01000 00000 100000 R-type (register) instruction format (32 bits): op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits +

Representing Instructions (Memory) C code: temp = A[8]; (A is an int array) MIPS assembly instruction: lw $t0, 32($s3) # lw rt,offset(rs): rt=mem[rs+offset] Machine language instruction: 100011 10011 01000 0000000000100000 I-type instruction format (32 bits): Note: the immediate field is coded is 2’s complement op rs rt immediate value / address offset 6 bits 5 bits 5 bits 16 bits

The Stored-Program Concept Machine Instructions are represented as 32 bit numbers. Programs are stored in memory as a sequence of instructions. The processor executes instructions in sequence: The Program Counter (PC) contains the memory address of the next instruction to execute. For each instruction PC is incremented by 4.

Next instruction at PC+4 The Program Counter Instruction Memory 4 8 12 16 PC = 8 Instruction Next instruction at PC+4

Conditional Branches and Unconditional Jumps C code: if (i == j) f = g + h; else f = g – h; bne $s3, $s4, Label_1 # if (i  j) Go to Label_1 # “Label_1” : offset from PC to the # label below add $s0,$s1,$s2 j Label_2 # Always go to Label_2 Label_1: sub $s0,$s1,$s2 Label_2: … + - T F

Conditional Branch instructions Branches can test for equality: bne a,b,Label # go to Label if a != b beq a,b,Label # go to Label if a == b But cannot test for a<b, etc. Must be done using other instructions. The slt R-type instruction is used for a<b tests: slt $t0,a,b # $t0 = 1 if a<b else 0 bne $t0,$zero, Label # go to Label if $t0 != 0 (a<b) Register 0 ($zero) always contains a zero.

Representing Instructions (Branch) C code: if (a == b) go to LABEL; MIPS assembly instruction: [0x0000009C] beq $s1,$s2,label # if $s1==$s2 PC+=4+(25*4) [0x000000A0] nop [0x00000104] label: Machine language instruction: 000100 10001 10010 0000000000011001 (25) I-type instruction format (32 bits): beq … label: nop 25 Instructions (of 1 word each) op rs rt immediate value / address offset 6 bits 5 bits 5 bits 16 bits

Representing Instructions (Jumps) C code: go to LABEL; MIPS assembly instruction: j 10000 # PC = PC[31:28] & (2500*4) Machine language instruction: 000010 00000000000000100111000100 (2500) J-type instruction format (32 bits): op jump target address 6 bits 26 bits New target address: 4 bits (PC) + 26 bits (Instruction) + 2 bits (’00’)

Other Jump Instructions Jump (J-type): j 10000 # jump to address 10000 Jump Register (NB: R-type!): jr rs # jump to 32 bit address in register rs Jump and Link (J-type): jal 10000 # jump to 10000 and save PC in R31 Use jal for procedure calls, it saves the return address (PC+4) in register 31 ($ra) Use “jr $ra” to return from subroutine Nested procedures must save $ra on a stack, and should use registers $sp (stack pointer) and $fp (frame pointer) manage the stack.

Immediate data instructions (I-type) Add Immediate: addi $sp,$sp,4 # add rt,rs,const : rt=rs+const NB: The constant is sign extended to 32 bits first! Load Upper Immediate: lui $s0,61 # rt = 61 << 16 (low bits zeroed) Can be used together with e.g. addi, ori to produce 32 bit constants. Load Immediate is not a machine instruction! The assembler has “li”, but it’s a pseudo-instruction that is expanded into lui and ori.

Summary of MIPS addressing modes Register addressing Used by R-type instructions (add,sub) Immediate addressing Used by immediate I-type instructions (addi,ori) Base addressing Used by I-type instructions (lw,sw,lb,sb) PC-relative addressing Used by branching I-type instructions (beq,bne) Pseudodirect addressing Used by J-type jump instructions (j,jal)

Summary of MIPS instruction formats R-type (add, sub, slt, jr) I-type (beq, bne + addi, lui + lw, sw) J-type (j, jal) op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits op rs rt immediate value / address offset 6 bits 5 bits 5 bits 16 bits op jump target address 6 bits 26 bits

Running a C program C source file + headers Dynamic library files C compiler Machine language program in memory Assembler file Loader (OS) Assembler Executable file RUN! Object code file Other object files Linker Static library files

MIPS memory map convention 7ffffffc 10010000 10000000 00400000 00000000 $sp=7ffffffc Stack Dynamic data Note: Hex addresses Static data $gp=10008000 Text (Program) PC=00400000 Reserved (for OS)

Hexadecimal Notation Dec Bin Hex 0000 8 1000 1 0001 9 1001 2 0010 10 0000 8 1000 1 0001 9 1001 2 0010 10 1010 A 3 0011 11 1011 B 4 0100 12 1100 C 5 0101 13 1101 D 6 0110 14 1110 E 7 0111 15 1111 F