CS3350B Computer Architecture MIPS Introduction

Similar documents
CS3350B Computer Architecture

CS3350B Computer Architecture MIPS Instruction Representation

Chapter 2A Instructions: Language of the Computer

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Course Administration

Computer Architecture

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Instructions: Language of the Computer

MIPS (SPIM) Assembler Syntax

CS222: MIPS Instruction Set

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

COMPUTER ORGANIZATION AND DESIGN

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Chapter 2: Instructions:

Computer Organization MIPS ISA

MIPS Instruction Set Architecture (1)

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

Architecture I. Computer Systems Laboratory Sungkyunkwan University

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

EECS Computer Organization Fall Based on slides by the author and prof. Mary Jane Irwin of PSU.

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

CSEE 3827: Fundamentals of Computer Systems

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CS/COE1541: Introduction to Computer Architecture

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Chapter 2. Instructions: Language of the Computer

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Instructions: Language of the Computer

ECE 154A Introduction to. Fall 2012

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Chapter 2. Instruction Set Architecture (ISA)

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Course Administration

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

MIPS%Assembly% E155%

Chapter 1. Computer Abstractions and Technology

ECE232: Hardware Organization and Design

Control Instructions

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Chapter 3. Instructions:

Thomas Polzer Institut für Technische Informatik

Unsigned Binary Integers

Unsigned Binary Integers

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

LECTURE 2: INSTRUCTIONS

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Lecture 4: MIPS Instruction Set

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Computer Architecture. The Language of the Machine

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Chapter 2. Instructions:

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

CENG3420 Lecture 03 Review

Instruction Set Architecture. "Speaking with the computer"

Chapter 2. Baback Izadi Division of Engineering Programs

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

CS3350B Computer Architecture MIPS Procedures and Compilation

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Levels of Programming. Registers

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

Communicating with People (2.8)

Lectures 3-4: MIPS instructions

MIPS Assembly Programming

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Computer Architecture

ECE331: Hardware Organization and Design

Computer Architecture. MIPS Instruction Set Architecture

ECE 30 Introduction to Computer Engineering

EE 361 University of Hawaii Fall

EEC 581 Computer Architecture Lecture 1 Review MIPS

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

All instructions have 3 operands Operand order is fixed (destination first)

Instructions: Language of the Computer

Instruction Set Architectures Part I: From C to MIPS. Readings:

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Transcription:

CS3350B Computer Architecture MIPS Introduction Marc Moreno Maza http://www.csd.uwo.ca/~moreno/cs3350_moreno/index.html Department of Computer Science University of Western Ontario, Canada Thursday January 25, 2018

Abstraction of machine structures Levels of representation

Instructions: Language of the Computer

Instruction Set Machine instructions form the language of the Computer, known as the instruction set Different computers have different instruction sets: but with many aspects in common; early computers had very simple instruction sets due to simplified implementation w.r.t. today s computers Nevertheless, many modern computers also have simple instruction sets

The MIPS instruction set Used as the example throughout this course For history, see https: //en.wikipedia.org/wiki/mips_instruction_set MIPS stand for Microprocessor without Interlocked Pipeline Stages. MIPS has a large share of the embedded core market Applications in consumer electronics, network/storage equipment, cameras, printers,... MIPS is typical of many modern ISAs See the MIPS Reference card.

spim assembler and simulator spim is a simulator that runs MIPS32 assembly language programs It provides a simple assembler, debugger and a simple set of operating system services Interfaces: Spim, XSpim, PCSpim, QtSpim (new UI, cross-platform) See installation and user guide at http://pages.cs.wisc.edu/~larus/spim.html We recommand to use the command line versions: Spim and XSpim

Arithmetic operations Add and subtract have three operands two sources and one destination add a, b, c # a gets b + c All arithmetic operations have this form Design principle 1: simplicity favors regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost

ArithmeticeExample C code: f = (g + h) - (i + j); Compiled MIPS code: add t0, g, h # temp t0 = g + h add t1, i, j # temp t1 = i + j sub f, t0, t1 # f = t0 - t1

Register Operands Arithmetic instructions use register operands MIPS has a 32 32-bit register file use for frequently accessed data numbered 0 to 31 32-bit data called a word Assembler names $t0, $t1,... $t9 for temporary values $s0, $s1,... $s7 for saved variables Design Principle 2: smaller is faster in comparison ot main memory which has millions of locations

Register operand example C code: f = (g + h) - (i + j); f,..., j in $s0,..., $s4 Compiled MIPS code: add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s0, $t0, $t1

Memory operands Main memory used for storing composite data: Arrays, structures, dynamic data To apply an arithmetic operation, we need to load values from memory into registers, and store the result from register to memory Memory is byte addressable Each address identifies a word (= 4 bytes = 32 bits) each word is aligned in memory, that is, its address must be a multiple of 4 MIPS is Big Endian that is, it stores the most significant byte in the smallest address, in contrast, with little endian, the least-significant byte is at the smallest address. Read https://en.wikipedia.org/wiki/endianness

Memory operand example 1 C code: g = h + A[8]; assume g in $s1, h in $s2, and the base address of A in $s3 Compiled MIPS code: With 4 bytes per word, the index 8 requires an offset of 32 lw $t0, 32($s3) # load word add $s1, $s2, $t0

Memory Operand example 2 C code: A[12] = h + A[8]; h in $s2, base address of A in $s3 Compiled MIPS code: lw $t0, 32($s3) # load word add $t0, $s2, $t0 sw $t0, 48($s3) # store word

Registers vs. memory Registers are faster to access than memory Operating on memory data requires loads and stores Thus more instructions to be executed Compiler must use registers for variables as much as possible only spill to memory for less frequently used variables register optimization is important!

Immediate operands Constant data specified in an instruction addi $s3, $s3, 4 There is no subtract immediate instruction just use a negative constant addi $s2, $s1, -1 Design Principle 3: make the common case fast small constants are common immediate operand avoids a load instruction

The constant zero MIPS register 0 ($zero) is the constant 0 Cannot be overwritten Useful for common operations for instance, for copying between registers add $t2, $s1, $zero

Overview: MIPS R3000 ISA Instruction categories computational load/store jump and Branch floating point coprocessor memory management special 3 basic instruction formats: all 32 bits wide OP rs rt rd sha funct R-format OP rs rt immediate I-format OP jump target J-format

MIPS ISA: selected instructions Category Instr OP/ Example Meaning funct Arithmetic add R 0/32 add $s1, $s2, $s3 $s1 = $s2 + $s3 subtract R 0/34 sub $s1, $s2, $s3 $s1 = $s2 - $s3 add immediate I 8 addi $s1, $s2, 6 $s1 = $s2 + 6 or immediate I 13 ori $s1, $s2, 6 $s1 = $s2 6 Data load word I 35 lw $s1, 24($s2) $s1 = Memory($s2+24) Transfer store word I 43 sw $s1, 24($s2) Memory($s2+24) = $s1 load byte I 32 lb $s1, 25($s2) $s1 = Memory($s2+25) store byte I 40 sb $s1, 25($s2) Memory($s2+25) = $s1 load upper imm I 15 lui $s1, 6 $s1 = 6 * 2 16 Cond. br on equal I 4 beq $s1, $s2, L if ($s1==$s2) go to L Branch br on not equal I 5 bne $s1, $s2, L if ($s1!= $s2) go to L set on less than R 0/42 slt $s1, $s2, $s3 if ($s2<$s3) $s1=1 else $s1=0 set on less than I 10 slti $s1, $s2, 6 if ($s2<6) $s1=1 immediate else $s1=0 Uncond. jump J 2 j 250 go to 1000 Jump jump register R 0/8 jr $t1 go to $t1 jump and link J 3 jal 250 go to 1000; $ra=pc+4

MIPS register convention Name Register Usage Preserve Number on call? $zero 0 constant 0 (hardware) n.a. $at 1 reserved for assembler n.a. $v0 - $v1 2-3 returned values no $a0 - $a3 4-7 arguments yes $t0 - $t7 8-15 temporaries no $s0 - $s7 16-23 saved values yes $t8 - $t9 24-25 temporaries no $k 26-27 Interrupt/trap handler yes $gp 28 global pointer yes $sp 29 stack pointer yes $fp 30 frame pointer yes $ra 31 return addr (hardware) yes

Unsigned binary integers Given an n-bit number x = x n 1 2 n 1 + x n 2 2 n 2 + + x 1 2 1 + x 0 2 0 Range: 0 to + 2 n 1 Example 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0 2 2 + 1 2 1 + 1 2 0 = 0 + + 8 + 0 + 2 + 1 = 11 10 Using 32 bits: 0 to +4,294,967,295

2s-complement signed integers Given an n-bit number x = x n 1 2 n 1 + x n 2 2 n 2 + + x 1 2 1 + x 0 2 0 Range: -2 n 1 to +2 n 1-1 Example 1111 1111 1111 1111 1111 1111 1111 1100 2 = 1 2 31 + 1 2 30 + + 1 2 2 + 0 2 1 + 0 2 0 = 2, 147, 483, 648 + 2, 147, 483, 644 = 4 10 Using 32 bits: -2,147,483,648 to +2,147,483,647

2s-complement signed integers Bit 31 is sign bit 1 for negative numbers 0 for non-negative numbers -(-2 n - 1) can t be represented Non-negative numbers have the same unsigned and 2s-complement representation Some specific numbers 0: 0000 0000... 0000-1: 1111 1111... 1111 Most-negative: 1000 0000... 0000 Most-positive: 0111 1111... 1111

Signed negation Complement and add 1 Complement means 1 0, 0 1 x + x = 1111... 111 2 = 1 x + 1 = x Example: negate +2 +2 = 0000 0000... 00102 2 = 1111 1111... 11012 + 1 = 1111 1111... 1110 2

Sign extension Representing a number using more bits Preserve the numeric value In MIPS instruction set addi: extend immediate value lb, lh: extend loaded byte/halfword Replicate the sign bit to the left unsigned values are extended with 0s Examples: 8-bit to 16-bit +2: 0000 0010 0000 0000 0000 0010-2: 1111 1110 1111 1111 1111 1110