Operations, Operands, and Instructions

Similar documents
Unsigned Binary Integers

Unsigned Binary Integers

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

CSEE 3827: Fundamentals of Computer Systems

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Chapter 2A Instructions: Language of the Computer

CSCI 402: Computer Architectures

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

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

Instructions: Language of the Computer

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

Levels of Programming. Registers

CS222: MIPS Instruction Set

EC 413 Computer Organization

Chapter 2: Instructions:

IC220 SlideSet #2: Instructions (Chapter 2)

Instructions: Language of the Computer

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

Chapter 1. Computer Abstractions and Technology

CS3350B Computer Architecture MIPS Introduction

CS3350B Computer Architecture

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

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

ECE 154A Introduction to. Fall 2012

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

CS3350B Computer Architecture MIPS Instruction Representation

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

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

ECE260: Fundamentals of Computer Engineering

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

(Refer Slide Time: 1:40)

ECE260: Fundamentals of Computer Engineering

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

Assembler. Lecture 8 CS301

Instruction encoding. MIPS Instruction encoding

CS 61c: Great Ideas in Computer Architecture

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

ECE331: Hardware Organization and Design

ECE 486/586. Computer Architecture. Lecture # 7

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

Architecture I. Computer Systems Laboratory Sungkyunkwan University

ECE232: Hardware Organization and Design

Five classic components

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

Number System. Introduction. Decimal Numbers

Instruction Set Architecture

Computer Organization MIPS ISA

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

Brock Wilcox CS470 Homework Assignment 2

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

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

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

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

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

syscall takes a service ID (number) in $v0 Read integer $v0=5, after syscall, $v0 holds the integer read from keyboard

Computer Architecture

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

ECE232: Hardware Organization and Design

Lectures 3-4: MIPS instructions

ISA: The Hardware Software Interface

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

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

CS61C : Machine Structures

Instructions: Language of the Computer

Chapter Two MIPS Arithmetic

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

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

Computer Architecture

CS61C : Machine Structures

UCB CS61C : Machine Structures

Chapter 4. The Processor

MIPS%Assembly% E155%

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

CS 4200/5200 Computer Architecture I

Computer Organization and Components

MIPS Instruction Set Architecture (1)

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

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

Computer Hardware Engineering

Lecture 4: MIPS Instruction Set

CS 430 Computer Architecture. C/Assembler Arithmetic and Memory Access William J. Taffe. David Patterson

Part 1 (70% of grade for homework 2): MIPS Programming: Simulating a simple computer

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

Integer Representation

M1 Computers and Data

COMPUTER ORGANIZATION AND DESIGN

Chapter 2. Instruction Set Architecture (ISA)

Chapter 4. The Processor Designing the datapath

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

MIPS Memory Access Instructions

Instruction Set Architecture

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

Chapter 4. The Processor. Computer Architecture and IC Design Lab

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

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

CS 261 Fall Mike Lam, Professor Integer Encodings

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

Course Administration

Chapter 4. The Processor

Transcription:

Operations, Operands, and Instructions Tom Kelliher, CS 220 Sept. 12, 2011 1 Administrivia Announcements Assignment Read 2.6 2.7. From Last Time Macro-architectural trends; IC fab. Outline 1. Introduction. 2. Simple arithmetic operations 3. Operands: registers, memory. 4. R-Format and I-Format instruction formats. 1

Coming Up Logical and conditional instructions in MIPS. 2 Introduction 1. Stored program concept. Is it data, address of data, instruction, or what? 2. Instruction set. 3. Operands. 4. Collected design principles: (a) Simplicity favors regularity. A simple architecture will result in regular, clean implementations. Example: arithmetic operations that have two source operands. (b) Smaller is faster. Storage capacity vs. speed tradeoffs. Examples: Register file size. Word size. Instruction set cardinality. (c) Make the common case fast. Example: The most common immediate values are small. Store them in the instruction. (d) Good design demands good compromises. We can t optimize everything. Example: Having only a few instruction formats, all of which are regular. 3 Arithmetic Instructions Instruction semantics: 2

add a, b, c sub a, a, b # This, BTW, is a comment. De-compile into a single HLL statement: add a, b, c add a, a, d add a, a, e Compile each of the following: a = b + c; d = a - e; f = (g + h) - (i + j); 4 Instruction Operands Where are the operands? 4.1 Registers $0 to $31 or $s0, $t0, etc. Example: add $1, $2, $3 Properties of registers: 1. Number of registers. 32 for MIPS, including the hardwired register. Two ways of naming: numbers, convention nicknames. Why not more? Size of register file, size of operand fields within instructions. 3

2. Number of bits/register. 32. Word size. 32 bits is 4 bytes. Implications: size of address space, datapath width. 3. General purpose vs. special purpose. MIPS, M68000, x86. 4.2 Memory Operands 1. HLL have complex data structures such as arrays and structs. How are they handled? 2. Data transfer instructions: load, store. operands: memory address, register. 3. Actual MIPS instructions: lw, sw. Base and offset addressing: lw $s0, 8($s1) See baseoffset lab. 4. MIPS memory is byte addressable, so word addresses differ by 4: Word Address 0 4 8 12 Byte Address 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 msb lsb Alignment restriction Word addresses start on word boundaries. A good compromise. This isn t the only way to number the bytes within word. Big endian. Base, offset addressing. Usefulness when accessing a member of an object. Compile each of the following: 4

A[12] = h + A[8]; A[j] = h + A[i]; where h is in $1, i is in $2, j is in $3, and the base address of A, an int array of 100 words, is in $4. Variables in registers are simpler to use and faster than variables in memory. Compilers must be clever in optimizing register use. Example: lw $1, 4($0) lw $2, 8($0) add $1, $1, $2 sw $1 0($0) Explain what this is doing, in plain English. Another example: lw $t0, 0($s0) addi $s0, $s0, 4 lw $t1, 0($s0) add $t0, $t0, $t1 addi $s0, $s0, 4 sw $t0, 0($s0) Again, explain. 5 Representing Numbers Basics: 1. Conventional number systems are weighted and positional. 5

2. A base x systems uses x numerals (symbols). 3. Representing negative values is tricky we cheat in decimal. 4. The hexadecimal system and its relationship to binary. 5. Base conversions. 6. msb and lsb. 5.1 Unsigned Integers 1. Consider a four bit unsigned binary integer: b 3 b 2 b 1 b 0. What does b i contribute to the value of the number? 2. What range of values can be represented using just four bits? Eight bits? n bits? 5.2 Signed Integers How might we designate that a binary number is negative? Two problems with this approach: 1. Two representations for zero. 2. Adder design becomes more difficult. This is sign-magnitude representation. 5.3 Two s Complement Representation Again, msb is sign bit. 1. Positive values have same representation as for unsigned case. 6

2. To compute the inverse, complement all the bits and add 1. 3. One 0. 4. Asymmetric range: one more negative value. 5.4 Two s Complement: Negation, Sign Extension 1. Negation: (a) Two s complement is called by that name because 2 n x = x Which is okay because 2 n = 0. Wait Why? Obviously, (2 n 1) x = x So: x = 2 n x = (2 n 1) x+1 = x + 1 Hence our algorithm for negating a two s complement number. 2. Sign Extension: (a) How do you place a 16-bit signed immediate into a register? (b) How do you load a signed byte into register? (c) The sign extension algorithm. (d) Load byte unsigned. (e) How can this simple procedure preserve the value of a negative number? Proof? 3. Signed & unsigned comparison. Or, sometimes 1111 is less than 0000 and sometimes it s not. 7

6 Representing Instructions 6.1 MIPS R-Format Example instruction: add $s2, $s0, $s1 26 21 16 11 6 Op Rs Rt Rd Shamt Func 6 5 5 5 5 6 Fields: 1. Op: Opcode. 2. Rs: First source operand. 3. Rt: Second source operand. 4. Rd: Destination operand. 5. Shamt: Shift amount ignore for now. 6. Func: Function. Further specification of the opcode. In assembly: Op/Func Rd, Rs, Rt Notes: 1. Become familiar with field positions and sizes for all three formats. 2. Example encodings: Assembly Op Rs Rt Rd Shamt Func add $1, $2, $3 0 2 3 1 D.C. 32 sub $4, $5, $6 0 5 6 4 D.C. 34 8

6.2 MIPS I-Format Example instruction: lw $s0 8($s1) 26 21 16 0 Op Rs Rt Immediate 6 5 5 16 Fields: 1. Op: Opcode. 2. Rs: Source register. 3. Rt: Destination register. 4. Address: 16-bit signed immediate value. Offset range? Example encoding of: A[20] += 72; Assembly Op Rs Rt Immediate lw $t1, 80($s0) 35 16 9 80 addi $t2, $t1, 72 8 9 10 72 sw $t2, 80($s0) 43 16 10 80 9