Computer Instructions

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

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
CS/COE0447 Computer Organization & Assembly Language
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
ELEN 468 Advanced Logic Design
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
The University of Adelaide, School of Computer Science
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
1 Instruction Set Architecture (ISA) Alexander Titov 10/20/2012.
Lecture 4: MIPS Instruction Set
Computer Architecture and Organization
Computer Architecture EKT 422
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
MIPS Instructions Instructions: Language of the Machine
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
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
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS Assembly.
Lecture 5: Procedure Calls
Computer Architecture Instruction Set Architecture
CS2100 Computer Organisation
COMPUTER ARCHITECTURE & OPERATIONS I
Morgan Kaufmann Publishers
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
32-bit MIPS ISA.
The University of Adelaide, School of Computer Science
ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Instructions - Type and Format
Appendix A Classifying Instruction Set Architecture
Single-Cycle CPU DataPath.
Lecture 4: MIPS Instruction Set
The University of Adelaide, School of Computer Science
Systems Architecture Lecture 5: MIPS Instruction Set
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
Lecture 5: Procedure Calls
ECEG-3202 Computer Architecture and Organization
COMS 361 Computer Organization
Computer Architecture
3.
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
CS352H Computer Systems Architecture
Introduction Lab1 A crash course in assembler programming
9/27: Lecture Topics Memory Data transfer instructions
MIPS Processor.
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Computer Instructions CSE 410, Spring 2008 Computer Systems http://www.cs.washington.edu/410 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Reading and References Readings Computer Organization and Design Section 2.1, Introduction Section 2.2, Operations of the Computer Hardware Section 2.3, Operands of the Computer Hardware Section 2.4, Representing Instructions Other References Google MIPS tutorials See MIPS Run, D Sweetman section 8.6, Instruction encoding section 10.2, Endianness 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Today’s Agenda //pick a language A = B + C; //say, c Lets convert this to a much more primitive programming language Assume A,B,C are associated with $t0,$t1,$t2 add $t0, $t1, $t2 #say, MIPS 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

A very simple organization main memory program counter registers functional units 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Instructions in main memory Instructions are stored in main memory this is simply a contiguous array of words Byte addressable: each byte in memory has a number (an address) Program counter (PC) points to the next instruction All MIPS instructions are 4 bytes long, and so instruction addresses are always multiples of 4 Program addresses are 32 bits long 232 = 4,294,967,296 = 4 GigaBytes (GB) 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Instructions in memory ... ... ... ... ... 20 16 instruction addresses 12 8 4 instruction value instruction value 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Fetch/Execute Cycle (Preview) Operation of a computer: while (processor not halted) { fetch instruction at memory location (PC) PC = PC + 4 (increment to point to next instruction) execute fetched instruction } Instructions execute sequentially unless a jump or branch changes the PC to cause the next instruction to be fetched from somewhere else Similar to game-loop logic 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Some common storage units Note that a byte is 8 bits on almost all machines. The definition of word is less uniform (4 and 8 bytes are common today). A nibble is 4 bits (half a byte!) unit # bits byte 8 half-word 16 word 32 double word 64 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Alignment An object in memory is “aligned” when its address is a multiple of its size Byte: always aligned Halfword: address is multiple of 2 Word: address is multiple of 4 Double word: address is multiple of 8 Alignment simplifies load/store hardware 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

System organization so far main memory instructions and data program counter increments by 4 32-bit instructions registers functional units 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

MIPS Registers 32 bits wide easy to access and manipulate 32 bits is 4 bytes same as a word in memory signed values from -231 to +231-1 unsigned values from 0 to 232-1 easy to access and manipulate Fast to access *and* more useful than memory 32 registers (not related to being 32 bits wide) But is related to 2^5 = 32 on chip, so very fast to access Fastest in the memory hierarchies we’ll study in class 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Register addresses 32 general purpose registers how many bits does it take to identify a register? 5 bits, because 25 = 32 32 registers is a compromise selection more would require more bits to identify fewer would be harder to use efficiently 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Register numbers and names usage zero always returns 0 1 at reserved for use as assembler temporary 2-3 v0, v1 values returned by procedures 4-7 a0-a3 first few procedure arguments 8-15, 24, 25 t0-t9 temps - can use without saving 16-23 s0-s7 temps - must save before using 26,27 k0, k1 reserved for kernel use - may change at any time 28 gp global pointer 29 sp stack pointer 30 fp or s8 frame pointer 31 ra return address from procedure 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

How are registers used? Many instructions use 3 registers For example 2 source registers 1 destination register For example add $t1, $a0, $t0 add a0 and t0 and put result in t1 add $t1,$zero,$a0 move contents of a0 to t1 (t1 = 0 + a0) 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

R-Type instructions: 3 registers Add $t0, $t1, $t2 32 bits available in the instruction 15 bits for the three 5-bit register numbers The remaining 17 bits are available for specifying the instruction 6-bit op code - basic instruction identifier 5-bit shift amount (2^5=32, meaning?) 6-bit function code 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

R-Type fields some common R-Type instructions op code source 1 source 2 dest shamt function 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits some common R-Type instructions arithmetic: add, sub, mult, div logical: and, or, sll, srl comparison: slt (set on less than) jump through register: jr 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Bits are just bits The bits mean whatever the designer says they mean when the ISA is defined How many possible 3-register instructions are there? 217 = 131,072 includes all values of op code, shamt, function As the ISA develops over the years, the encoding tends to become less logical *cough, cough* intel 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

System organization again main memory instructions and data program counter increments by 4 32-bit instructions registers 32 bits wide 32 in number functional units implement instructions 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Transfer from memory to register Load instructions word: lw rt, address half word: lh rt, address lhu rt, address byte: lb rt, address lbu rt, address signed load => sign bit is extended into the upper bits of destination register unsigned load => 0 in upper bits of register 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Transfer from register to memory Store instructions word: sw rt, address half word: sh rt, address byte: sb rt, address 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

The “address” term There is one basic addressing mode: offset + base register value Offset is 16 bits ( 32 KB) Load word pointed to by s0, add t1, store lw $t0,0($s0) add $t0,$t0,$t1 sw $t0,0($s0) 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

offset or immediate value I-Type fields op code base reg src/dest offset or immediate value 6 bits 5 bits 5 bits 16 bits The contents of the base register and the offset value are added together to generate the address for the memory reference Can also use the 16 bits to specify an immediate value, rather than an address 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Instructions and Data flow main memory instructions and data program counter increments by 4 instructions and data registers 32 bits wide 32 in number functional units implement instructions 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

The eye of the beholder Bit patterns have no inherent meaning A 32-bit word can be seen as a signed integer ( 2 Billion) an unsigned integer or address pointer (0 to 4B) a single precision floating point number four 1-byte characters an instruction Four ASCII characters 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

offset or immediate value R-Type V.S. I-Type op code source 1 source 2 dest shamt function 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits op code base reg src/dest offset or immediate value 6 bits 5 bits 5 bits 16 bits 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

offset or immediate value R-Type V.S. I-Type op code source 1 source 2 dest shamt function 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 2 vs 3 regs, no shift, only opcode op code base reg src/dest offset or immediate value 6 bits 5 bits 5 bits 16 bits What if we tried an offset or immediate stuffed into shamt? What if we tried to index an array (immediate) using function? If we tried to jump or branch using function? What about I-Type offset? What if we had a new instruction type for Jump, and the first bit of the opcode indicates this, the rest is the jump address (or offset) – how far can we jump? 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Big-endian, little-endian A 32-bit word in memory is 4 bytes long but which byte is which address? Consider the 32-bit number 0x01234567 four bytes: 01, 23, 45, 67 most significant bits are 0x01 least significant bits are 0x67 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Data in memory- big endian Big endian - most significant bits are in byte 0 of the word byte # contents ... ... ... ... ... 7 67 12 6 45 8 5 23 4 01 23 45 67 4 01 1 2 3 byte offsets 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington

Data in memory- little endian Little endian - least significant bits are in byte 0 of the word byte # contents ... ... ... ... ... 7 01 12 6 23 8 5 45 4 01 23 45 67 4 67 3 2 1 byte offsets 2/16/2019 cse410-02-instructions © 2006-07 Perkins, DWJohnson & University of Washington