Instructions: Language of the Computer

Similar documents
MIPS Memory Access Instructions

Instructions: Language of the Computer

Computer Organization MIPS ISA

Course Administration

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CENG3420 Lecture 03 Review

Chapter 2A Instructions: Language of the Computer

Computer Architecture

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

Chapter 2: Instructions:

CENG3420 L03: Instruction Set Architecture

CS3350B Computer Architecture MIPS Instruction Representation

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

Instructions: Language of the Computer

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

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

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

CS222: MIPS Instruction Set

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

Control Instructions

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

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

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

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

Chapter 3. Instructions:

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

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

Chapter 2. Instruction Set Architecture (ISA)

Reduced Instruction Set Computer (RISC)

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

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

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

Reduced Instruction Set Computer (RISC)

Chapter 2. Instructions:

Topic Notes: MIPS Instruction Set Architecture

Computer Architecture. MIPS Instruction Set Architecture

CS3350B Computer Architecture MIPS Introduction

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

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

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

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

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

Lecture 4: MIPS Instruction Set

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

CS3350B Computer Architecture

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

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

Instruction Set Architecture. "Speaking with the computer"

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

MIPS Instruction Set Architecture (1)

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

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

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

MIPS%Assembly% E155%

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

Thomas Polzer Institut für Technische Informatik

MIPS (SPIM) Assembler Syntax

Levels of Programming. Registers

CS222: Dr. A. Sahu. Indian Institute of Technology Guwahati

CS/COE1541: Introduction to Computer Architecture

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

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Computer Architecture. The Language of the Machine

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

Review of instruction set architectures

COMPUTER ORGANIZATION AND DESIGN

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

Chapter 2. Instructions: Language of the Computer

EC 413 Computer Organization

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Lectures 3-4: MIPS instructions

Unsigned Binary Integers

Unsigned Binary Integers

Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.)

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

Computer Architecture

ECE369. Chapter 2 ECE369

ECE331: Hardware Organization and Design

ECE 154A Introduction to. Fall 2012

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

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

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

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

ECE232: Hardware Organization and Design

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

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

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

Systems Architecture I

CSEE 3827: Fundamentals of Computer Systems

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

Lecture 4: Instruction Set Architecture

Transcription:

CS359: Computer Architecture Instructions: Language of the Computer Yanyan Shen Department of Computer Science and Engineering 1

The Language a Computer Understands Word a computer understands: instruction Vocabulary of all words a computer understands: instruction set (aka instruction set architecture or ISA) Different computers may have different vocabularies (i.e., different ISAs) iphone (ARM) not same as Macbook (x86) Or the same vocabulary (i.e., same ISA) iphone and ipad computers have same instruction set (ARM) Instructions are represented as numbers and, as such, are indistinguishable from data 2

MIPS Instruction Fields MIPS fields are given names to make them easier to refer to op rs rt rd shamt funct op 6-bits opcode that specifies the operation rs 5-bits register file address of the first source operand rt 5-bits register file address of the second source operand rd 5-bits register file address of the result s destination shamt 5-bits shift amount (for shift instructions) funct 6-bits function code augmenting the opcode 3

MIPS (RISC) Design Principles Simplicity favors regularity fixed size instructions small number of instruction formats opcode always the first 6 bits Smaller is faster limited instruction set limited number of registers in register file limited number of addressing modes Make the common case fast arithmetic operands from the register file (load-store machine) allow instructions to contain immediate operands Good design demands good compromises three instruction formats 4

MIPS- ISA Instruction Categories Computational Load/Store Jump and Branch Floating Point Memory Management Special Registers R0 - R31 PC HI LO 3 Instruction Formats: all bits wide op op op rs rt rd sa funct rs rt immediate jump target R format I format J format 5

MIPS ISA Design MIPS Instruction Set has integer registers MIPS registers are bits wide MIPS calls this quantity a word Some computers use 16-bit or 64-bit wide words E.g., Intel 8086 (16-bit), MIPS64 (64-bit) 6

MIPS Register File Holds thirty-two -bit registers Two read ports One write port Registers are Faster than main memory src1 addr src2 addr dst addr write data - Read/write port increase impacts speed quadratically Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order Can hold variables so that - code density improves (since register are named with fewer bits than a memory location) 5 5 5 Register File bits location s write control src1 data src2 data 7

Aside: MIPS Register Convention Name Register Usage Number $zero 0 constant 0 (hardware) $at 1 reserved for assembler $v0 - $v1 2-3 returned values $a0 - $a3 4-7 arguments $t0 - $t7 8-15 temporaries $s0 - $s7 16-23 saved values $t8 - $t9 24-25 temporaries $gp 28 global pointer $sp 29 stack pointer $fp 30 frame pointer $ra 31 return addr (hardware) 8

MIPS Arithmetic Instructions MIPS assembly language arithmetic statement add $t0, $s1, $s2 sub $t0, $s1, $s2 Each arithmetic instruction performs one operation Each specifies exactly three operands that are all contained in the register file ($t0,$s1,$s2) destination source1 op source2 Instruction Format (R format) op rs rt td sa funct 9

MIPS Memory Access Instructions MIPS has two basic data transfer instructions for accessing memory lw $t0, 4($s3) #load word from memory sw $t0, 8($s3) #store word to memory The data is loaded into (lw) or stored from (sw) a register in the register file a 5 bit address The memory address a bit address is formed by adding the contents of the base address register to the offset value A 16-bit field meaning access is limited to memory locations within a region of ±2 15 (or,768 bytes) of the address in the base register 10

Machine Language - Load Instruction Load/Store Instruction Format (I format): lw $t0, 24($s3) 35 19 8 24 10 Destination address now in the rt field no longer in the rd field Offset is limited to 16 bits so can t get to every location in memory (with a fixed base address) 11

Byte Addresses Since 8-bit bytes are so useful, most architectures address individual bytes in memory Alignment restriction - the memory address of a word must be on natural word boundaries (a multiple of 4 in MIPS-) Big Endian: leftmost byte is word address E.g., IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA Little Endian: rightmost byte is word address Intel 80x86, DEC Vax, DEC Alpha (Windows NT) little endian byte 0 3 2 1 0 msb lsb 0 1 2 3 big endian byte 0 12

Aside: Loading and Storing Bytes MIPS provides special instructions to move bytes lb $t0, 1($s3) #load byte from memory sb $t0, 6($s3) #store byte to memory 0x28 19 8 16 bit offset What 8 bits get loaded and stored? load byte places the byte from memory in the rightmost 8 bits of the destination register - what happens to the other bits in the register? store byte takes the byte from the rightmost 8 bits of a register and writes it to a byte in memory - what happens to the other bits in the memory word? 13

Example of Loading/Storing Bytes Given following code sequence and memory state what is the state of the memory after executing the code? add $s3, $zero, $zero lb $t0, 1($s3) sb $t0, 6($s3) Memory 0x 0 0 0 0 0 0 0 0 0x 0 0 0 0 0 0 0 0 0x 0 0 0 0 0 0 0 0 0x 1 0 0 0 0 0 1 0 0x 0 1 0 0 0 4 0 2 0x F F F F F F F F 0x 0 0 9 0 1 2 A 0 Data 24 20 16 12 8 4 What value is left in $t0? (big endian) $t0 = 0x00000090 What word is changed in Memory and to what? (big endian) 0 Word Address (Decimal) mem(4) = 0xFFFF90FF What if the machine was little endian? $t0 = 0x00000012 mem(4) = 0xFF12FFFF 14

MIPS Immediate Instructions Small constants are used often in typical code Possible approaches? put typical constants in memory and load them create hard-wired registers (like $zero) for constants like 1 have special instructions that contain constants! addi $sp, $sp, 4 #$sp = $sp + 4 slti $t0, $s2, 15 Machine format (I format): 0x0A 18 8 0x0F The constant is kept inside the instruction itself! #$t0 = 1 if $s2<15 what about upper 16 bits? Immediate format limits values to the range +2 15 1 to -2 15 15

MIPS Control Flow Instructions MIPS conditional branch instructions: bne $s0, $s1, Lbl #go to Lbl if $s0 $s1 beq $s0, $s1, Lbl #go to Lbl if $s0=$s1 Example: if (i==j) h = i + j; bne $s0, $s1, Lbl1 add $s3, $s0, $s1 Lbl1:... Instruction Format (I format): 0x05 16 17 16 bit offset How is the branch destination address specified? 16

Specifying Branch Destinations Use a register (like in lw and sw) added to the 16-bit offset which register? Instruction Address Register (the PC) its use is automatically implied by instruction PC gets updated (PC+4) during the fetch cycle so that it holds the address of the next instruction limits the branch distance to -2 15 to +2 15-1 (word) instructions from the (instruction after the) branch instruction, but most branches are local anyway from the low order 16 bits of the branch instruction 16 offset sign-extend 00 PC 4 Add Add branch dst address? 17

In Support of Branch Instructions We have beq, bne, but what about other kinds of branches (e.g., branch-if-less-than)? For this, we need yet another instruction, slt Set on less than instruction: slt $t0, $s0, $s1 # if $s0 < $s1 then # $t0 = 1 else # $t0 = 0 Instruction format (R format): 0 16 17 8 0x24 Alternate versions of slt slti $t0, $s0, 25 # if $s0 < 25 then $t0=1... sltu $t0, $s0, $s1 # if $s0 < $s1 then $t0=1... sltiu $t0, $s0, 25 # if $s0 < 25 then $t0=1... 18

Aside: More Branch Instructions Can use slt, beq, bne, and the fixed value of 0 in register $zero to create other conditions less than blt $s1, $s2, Label slt $at, $s1, $s2 #$at set to 1 if bne $at, $zero, Label #$s1 < $s2 less than or equal to ble $s1, $s2, Label greater than great than or equal to bgt $s1, $s2, Label bge $s1, $s2, Label Such branches are included in the instruction set as pseudo instructions - recognized (and expanded) by the assembler Its why the assembler needs a reserved register ($at) 19

Other Control Flow Instructions MIPS also has an unconditional branch instruction or jump instruction: j label #go to label Instruction Format (J Format): 0x02 26-bit address from the low order 26 bits of the jump instruction 26 00 Why shift left by two bits? 4 PC 20

Aside: Branching Far Away What if the branch destination is further away than can be captured in 16 bits? The assembler comes to the rescue it inserts an unconditional jump to the branch target and inverts the condition beq $s0, $s1, L1 L2: bne j $s0, $s1, L2 L1 21

Summary Instructions: machine language MIP- ISA Register file R-type, I-type, J-type instruction formats Arithmetic, memory access, control flow Assembly language vs machine code 22