CSCI 402: Computer Architectures

Similar documents
Unsigned Binary Integers

Unsigned Binary Integers

ECE 154A Introduction to. Fall 2012

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

ECE260: Fundamentals of Computer Engineering

ECE260: Fundamentals of Computer Engineering

Chapter 2A Instructions: Language of the Computer

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

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

Instructions: Language of the Computer

CS3350B Computer Architecture MIPS Instruction Representation

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

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

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

Architecture I. Computer Systems Laboratory Sungkyunkwan University

Computer Architecture

COMPUTER ORGANIZATION AND DESIGN

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

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

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

CSEE 3827: Fundamentals of Computer Systems

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Chapter 2. Instructions: Language of the Computer

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

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

Computer Architecture. Lecture 2 : Instructions

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

Lecture 4: MIPS Instruction Set

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

ECE232: Hardware Organization and Design

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

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

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

CS3350B Computer Architecture

Operations, Operands, and Instructions

CS3350B Computer Architecture MIPS Introduction

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

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

Lecture Topics. Announcements. Today: The MIPS ISA (P&H ) Next: continued. Milestone #1 (due 1/26) Milestone #2 (due 2/2)

Chapter 1. Computer Abstractions and Technology

CSSE232 Computer Architecture. Logic and Decision Opera:ons

Chapter 2. Baback Izadi Division of Engineering Programs

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

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

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

Computer Architecture

MIPS%Assembly% E155%

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

MIPS Instruction Set Architecture (2)

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

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

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B

Sheet For the following C code: a = b + c; b = a + c; d = a b; Write an equivalent assembly MIPS program. Solution:

Topic Notes: MIPS Instruction Set Architecture

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

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

Reduced Instruction Set Computer (RISC)

Lecture 5: Procedure Calls

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

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

Computer Organization MIPS ISA

ECE 486/586. Computer Architecture. Lecture # 7

Thomas Polzer Institut für Technische Informatik

Five classic components

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

CS61C : Machine Structures

The MIPS Instruction Set Architecture

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

CS 61c: Great Ideas in Computer Architecture

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

Instructions: Language of the Computer

EE 109 Unit 8 MIPS Instruction Set

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

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

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

3. Instruction Set Architecture The MIPS architecture

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Course Administration

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

CS 4200/5200 Computer Architecture I

Reduced Instruction Set Computer (RISC)

Chapter 2. Instructions: Language of the Computer

MACHINE LANGUAGE. To work with the machine, we need a translator.

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

LECTURE 2: INSTRUCTIONS

Chapter 2. Instructions: Language of the Computer. Jiang Jiang

Midterm. Sticker winners: if you got >= 50 / 67

Computer Organization and Components

UCB CS61C : Machine Structures

A Processor! Hakim Weatherspoon CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

Transcription:

CSCI 402: Computer Architectures Instructions: Language of the Computer (2) Fengguang Song Department of Computer & Information Science IUPUI Memory Operands Two tribes: Big Endian: Most-significant byte stored in low address of memory Little Endian: Least-significant byte stored in low address of memory E.g., Intel machines 0x 12 34 56 78 2 1

Byte Swap Problem GH 3 EF 2 CD 1 AB 0 Big Endian increasing byte address AB 3 CD 2 EF 1 GH 0 Little Endian Memory layout of a number of ABCDEFGH Each system is self-consistent, but causes problems when they need communicate! How about one byte: 0xAB? Does endianness matter? 3 Memory Alignment Memory Alignment (2 nd issue) Although computers are byte-addressable, memory is organized in aligned words. Alignment An n-byte data type is at an address that is a multiple of n n may be 1, 2, 4, 8, 16 (power of 2) Compiler is responsible for maintaining aligned data objects Simplify hardware design and reduces memory access time Alignment: Require objects fall on address that is multiple of their size. Endianess is one issue. Aligned Cannot be put anywhere 0 1 2 3 Word? must be aligned with addresses=4*k Not Aligned 4 2

Now, Combine Endianness and Alignment When do you need to consider Endianess, Alignment?, 5 1st Example of Memory Operand C code (1 array operand): g = h + A[8]; //Array of words g in $s1, h in $s2, base address of A in $s3 Compiled MIPS code: Index 8 requires an offset of 32 lw $t0, 32($s3) add $s1, $s2, $t0 # load word offset base register 6 3

Memory Operand Example 2 C code (Now, 2 array operands): 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 7 Registers vs. Memory Registers are faster to access than memory And use less energy Operating on memory data requires loads and stores Require more instructions to be executed Compiler must utilize registers to store variables as much as possible Only spill to memory for less frequently used variables (called register spilling ) 8 4

Immediate (Constant) Operands This is the 3 rd type of operand. 50% of instructions take a constant as input Based on SPEC CPU2006 benchmark Then, how to specify immediate data in an instruction? addi $s3, $s3, 4 However, no subtract-immediate instruction We can use a negative constant that is, addi $s2, $s1, -1 Design Principle #3: Make the common case fast Instructions using small constants are very common Q: Why addi should be faster than add? Immediate operand avoids a load instruction 9 The Constant Zero MIPS Register 0 ($zero) stores the constant 0 It is a special register Cannot be overwritten Is useful for common operations e.g., move data between registers: $s1 -> $t1 add $t1, $s1, $zero Q: Since registers are so important, should vendors (Intel/AMD) increase #registers very quickly (e.g., similar to Moore s law)? Because registers are related to ISA. But ISA is changed very slowly. 10 5

Format of the lw/sw instruction lw $register Address Address is represented by: Offset($R) //what does it mean? Address = Offset (in bytes) + Value stored in $R Similarly, sw $register Address 11 So far: Instructions? operations? operands? 2.4-2.6 Number representation in HW (integer) Instruction representation in HW Logical operations in MIPS 12 6

2.4 How to Represent Unsigned Integers? Given an n-bit binary number: x n-1 x n-2 x 1 x 0 x = x + n-1 n-2 1 0 n- 12 + xn-22 +! + x12 x02 n Number the bits from right à left n Least significant bit à most significant bit. n Range: [0, 2 n 1] n Example n n 1011 2 = 1 2 3 + 0 2 2 +1 2 1 +1 2 0 = 8 + 0 + 2 + 1 = 11 10 MIPS uses 32 bits n 0 to 2 32-1 (i.e., +4,294,967,295) n Has issue of integer overflow What is wrong? unsigned int i; for(i = 1000; i >= 0; --i) { do_sth(); } 13 Next, How to Represent Signed Integers? Given an n-bit binary number, Leading bit=1 à Negative x n-1 x n-2 x 1 x 0 x = -x + n Range? n-1 n-2 1 0 n- 12 + xn-22 +! + x12 x02 2 n 1 to +2 n 1 1 n Example (a 32-bit signed integer) n 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 n MIPS uses 32 bits n 2,147,483,648 to +2,147,483,647 14 7

2s-Complement Signed Integers Bit 31 is called sign bit Imbalance issue: ( 2 n 1 ) can t be represented! Then what is it? Positive numbers have the same 2s-complement representation Some special numbers 0: 0000 0000 0000 1: 1111 1111 1111 Most-negative: 1000 0000 0000 Most-positive: 0111 1111 1111 15 How to Negate a Number Quickly Trick: Complement the number and add 1 Complement means 1 0, 0 1 Example: how to negate +2 10? n 2 = 0000 0000 0010 2 n 2 = 1111 1111 1101 2 + 1 = 1111 1111 1110 2 n If we negate the above number again? Question: But why this method works? x + x =1111...111 2 = 1 x +1= x 16 8

Sign Extension There is an issue to copy a shorter number to a longer register e.g., copy a 4-bit number to an 8-bit register You must preserve the original numeric value e.g., copy 0010 2 to an 8-bit register? e.g., copy 1110 2? I don t know In the MIPS instruction set lw: both are 32-bit, no problem lb: need to extend the loaded byte to 32 bits Sign extension: Replicate the sign bit to the left c.f. unsigned values: extend with 0s (e.g., lbu) Examples: 8-bit to 16-bit +2: 0000 0010 => 0000 0000 0000 0010 2: 1111 1110 => 1111 1111 1111 1110 17 How to Represent Instructions? We write add $s0, $s1, $s2, ß but it is assembly code Instructions are encoded in a binary format MIPS instruction? Encoded as a 32-bit word (fixed size) Has ONLY 3 instruction formats to encode opcode, register numbers, Need to map register names to register numbers $t0 $t7 are reg s 8 15 $t8 $t9 are reg s 24 25 $s0 $s7 are reg s 16 23 18 9

MIPS R-format Instructions op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits MIPS s instruction fields Always 32 bits op: operation code funct: function code (extends opcode) rs: 1st source register number rt: 2nd source register number rd: destination register number shamt: shift amount (0 for now) 19 An R-format Example op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits add $t0, $s1, $s2 $t0 $t7: reg s 8 15 $t8 $t9: 24 25 $s0 $s7: reg s 16 23 special $s1 $s2 $t0 0 add 0 17 18 8 0 32 000000 10001 10010 01000 00000 100000 00000010001100100100000000100000 2 = 02324020 16 20 10

Bitwise Logical Operations The following Instructions are used for Bitwise Manipulation Operation C Java MIPS Shift left << << sll Shift right >> >>> srl Bitwise AND & & and, andi Bitwise OR or, ori Bitwise NOT ~ ~ nor n Useful for extracting and inserting groups of bits in a word 21 sll $rd $rt #bits Bitwise Shift Operations (R-type) op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits Encoding: op=0, funct=0 or 2 shamt: how many positions to shift: 5 bitsà 32 possible amounts to shift rs: unused, rt: source operand; rd: dest Shift left logical (sll) Shift left and fill with 0 bits sll by i bits à multiplies by 2 i Shift right logical (srl) Shift right and fill with 0 bits srl by i bits à divides by 2 i (unsigned only) 22 11

Bitwise AND Operations AND is useful to mask bits in a word Reset some bits to 0 and $t0, $t1, $t2 $t2 $t1 $t0 0000 0000 0000 0000 0000 1101 1100 0000 0000 0000 0000 0000 0011 1100 0000 0000 0000 0000 0000 0000 0000 1100 0000 0000 23 Bitwise OR Operations OR is useful to include bits in a word Set some bits to 1, leave others unchanged or $t0, $t1, $t2 $t2 $t1 $t0 0000 0000 0000 0000 0000 1101 1100 0000 0000 0000 0000 0000 0011 1100 0000 0000 0000 0000 0000 0000 0011 1101 1100 0000 24 12

Bitwise NOT Operations NOT is useful to invert bits in a word Change 0 to 1, and 1 to 0 MIPS has NOR 3-operand instruction a NOR b means NOT ( a OR b ) nor $t0, $t1, $zero Register 0 $t1 $t0 0000 0000 0000 0000 0011 1100 0000 0000 1111 1111 1111 1111 1100 0011 1111 1111 25 Bitwise Logical Operations Problem 1: How to isolate a segment in a word? Method 1: use AND a static way Method 2: A shift left followed by a shift right more flexible Problem 2: Set the bits from 5 to 12 in a 32- Given an integer x, bit word? unsigned in mask = -1; mask = mask << 24; mask = mask >> 19; 00000 00000 11111 x = x mask; 26 13