Instruction Set-Intro

Slides:



Advertisements
Similar presentations
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Advertisements

Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
INSTRUCTION SET ARCHITECTURES
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
CS3350B Computer Architecture Winter 2015 Lecture 4
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
Chapter 2.
Normal C Memory Management °A program’s address space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
CS 61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Atmega32 Architectural Overview
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
MIPS assembly. Computer What’s in a computer? Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
Instruction Set Architecture
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
Chapter 2 Instructions: Language of the Computer Part I.
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
CHAPTER 6 Instruction Set Architecture 12/7/
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Computer Organization Instructions Language of The Computer (MIPS) 2.
MIPS assembly. Computer  What’s in a computer?  Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
CHAPTER 2 Instruction Set Architecture 3/21/
Computers’ Basic Organization
Computer Architecture & Operations I
Computer Architecture & Operations I
Atmega32 Architectural Overview
A Closer Look at Instruction Set Architectures
Instruction Set Architecture
Morgan Kaufmann Publishers
A Closer Look at Instruction Set Architectures
The University of Adelaide, School of Computer Science
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
MIPS Assembly.
CSCI206 - Computer Organization & Programming
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
CS170 Computer Organization and Architecture I
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
Systems Architecture Lecture 5: MIPS Instruction Set
MIPS assembly.
The University of Adelaide, School of Computer Science
A Closer Look at Instruction Set Architectures Chapter 5
Computer Architecture
What is Computer Architecture?
The University of Adelaide, School of Computer Science
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Introduction to Microprocessor Programming
Instructions in Machine Language
COMS 361 Computer Organization
What is Computer Architecture?
What is Computer Architecture?
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
CPU Structure CPU must:
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Instruction Set Architecture
CSE378 Introduction to Machine Organization
Presentation transcript:

Instruction Set-Intro Explain the difference between Harvard and Von Neumann architectures in a computer. Define instruction set Explain the concept of the source and destination registers for the MIPS instruction set. Using the MIPS instruction set, explain how to add a set of variables. Define the term computer register Define the term data transfer instruction Using the MIPS instruction set, initialize a register to a fixed value.

CS2710 Computer Organization

CS2710 Computer Organization Instruction Sets The vocabulary of commands understood by a given computer architecture. Different computers have different instruction sets But with many aspects in common, since generally computer hardware architectures are similar Design principle: “Simplicity favors regularity” Once you learn one instruction set, learning others is relatively easy “More like dialects than separate languages” Early computers had very simple instruction sets Simplified implementation Today, most modern computers also have simple instruction sets Design principle: “Smaller is faster” CS2710 Computer Organization

Operands and Operations in Math Highlight that 3 and 3 are operands Highlight that the + is the operation Highlight that 6 is the operation 3 + 2 The values 3 and 2 are the operands The operation is addition Highlight that 3 and 3 are operands Highlight that the + is the operation Highlight that 6 is the operation CS2710 Computer Organization

Mathematical Operations supported by typical instruction sets Addition Subtraction Multiplication Division What about yx ? CS2710 Computer Organization

The Stored Program Concept The idea that instructions (operations) and data (operands) of many types can both be stored in memory as numbers. John von Neumann, 1940’s CS2710 Computer Organization

Microcontroller Components Data and program instructions are stored in different memory spaces. Each memory space has a separate bus, which allows: Different timing, size, and structure for program instructions and data. Concurrent access to data and instructions. Clear partitioning of data and instructions (=> security) Data and instructions are both stored in a single main memory space The content of the memory is addressable by location (without regard to what is stored in that location – either data or instructions) Same timing/size/structure for accessing either data or instructions Non-concurrent access to data and instructions (rather, sequential) Allows data to be executed as instructions! (=>insecure) Harvard Architecture Assign data and program instructions to different memory spaces. Each memory space has a separate bus. This allows: -> Different timing, size, and structure for program instructions and data. -> Concurrent access to data and instructions. -> Clear partitioning of data and instructions (=> security) -> This makes it harder to program, because static data can be in the program space or in the data space. -> If the program space and the data space are incompatible, copying data is no longer a (<start>,len) dump. Remove? Microcontroller Components

The MIPS Instruction Set Used for most examples in textbook Will be used as example language for the course Stanford MIPS commercialized by MIPS Technologies (www.mips.com) Large share of embedded core market Applications in consumer electronics, network/storage equipment, cameras, printers, … Typical of many modern Instruction Set Architectures (ISA’s) See MIPS Reference Data tear-out card, and Appendixes B and E CS2710 Computer Organization

Java vs. MIPS Assembly Language Statement a = b + c; // assign sum of b and c to a add a, b, c # Adds the values b and c and places the sum in a. Note that add is the instruction A is the destination B is one of the operands C is the other operand All arithmetic operations have this form Design Principle 1: Simplicity favours regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost add is an assembly language mnemonic that represents the operation to be performed on the operands a, b, and c People are much better using mnemonics than operation code-values (opcodes) to represent operations. We use a program called an assembler to convert assembly language mnemonics into opcodes (machine instructions) Note: we’re cheating a bit here; this is not real MIPs assembly language (coming soon) We use compilers to convert Java/C/C++ to machine instructions. Note that add is the instruction A is the destination B is one of the operands C is the other operand All arithmetic operations have this form Design Principle 1: Simplicity favours regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost CS2710 Computer Organization

Another Java vs. MIPS Assembly Language Statement – multiple adds a = b + c + d; // assign sum of b, c and d to a How would you rewrite the above Java statement if you could only perform one addition per instruction? Note that add is the instruction A is the destination B is one of the operands C is the other operand All arithmetic operations have this form Design Principle 1: Simplicity favours regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost Each line of assembly contains at most, 1 instruction. “Smaller is faster” The MIPs add instruction has exactly 3 operands; no more and no less “Simplicity favors regularity” Note that add is the instruction A is the destination B is one of the operands C is the other operand All arithmetic operations have this form Design Principle 1: Simplicity favours regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost CS2710 Computer Organization

CS2710 Computer Organization Stepwise addition a = b + c + d; // assign sum of b, c and d to a add t0, b, c # Adds the values b and c and places the sum in t0. add a, t0, d # Adds the values t0 and d and places the sum in a. Note that add is the instruction A is the destination B is one of the operands C is the other operand All arithmetic operations have this form Design Principle 1: Simplicity favours regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost Each line of assembly contains at most, 1 instruction. “Smaller is faster” The MIPs add instruction has exactly 3 operands; no more and no less “Simplicity favors regularity” Note that add is the instruction A is the destination B is one of the operands C is the other operand All arithmetic operations have this form Design Principle 1: Simplicity favours regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost CS2710 Computer Organization

CS2710 Computer Organization In Java, we use variables (or literals) to represent operands In assembly, operands are restricted to a limited number of locations called registers (with exceptions to be discussed later) Register: A hardware part of the central processing unit used as a storage location. The storage capacity of a register is generally a single word. Word: The natural unit of data/instruction size (in bits) in a computer. A word normally corresponds to the size of a CPU register. In MIPs, a word is 32 bits CS2710 Computer Organization

CS2710 Computer Organization At right: a block diagram of a computer’s Central Processing Unit (CPU). Note: Although the areas not highlighted (Program Flash and SRAM) might sometimes be physically located on the same chip, they are generally not considered to be part of the CPU. These two elements are often absent from the microprocessor chip and instead located on nearby chips. They are combined on the same chip with the CPU primarily to reduce cost for simple systems. CS2710 Computer Organization

CS2710 Computer Organization MIPS Architecture Arithmetic instructions use (mainly) register operands MIPS has 32 32-bit registers Use for frequently accessed data Numbered 0 to 31 These registers are given special mnemonic designations, and are by convention, used as follows: $zero (by definition, contains the value 0) $s0-$s7 (for saved values) $at, $t0-$t7, $t8-$t9 (for temporary values) $a0-$a3 (arguments) $v0-v1 (return values) and others, see p 78 (fig 2.1) Also: see the green tear-off card that came with your text CS2710 Computer Organization

CS2710 Computer Organization Why registers? Q: What is the speed of light in a vacuum? Q: Do electrical signals always propagate at the speed of light? Q: How far can an electrical signal propagate in 0.25 ns? CS2710 Computer Organization

CS2710 Computer Organization Problem Java/C: f = (g + h)-(i + j); Assume f…j are in $s0…$s4 How might we do it in MIPs assembly? What would a Java/C compiler produce? li $t0, 6 ai $t1, 3 add $s0, $t0, $t1 li $t0, 6 ai $t1, 3 add $s0, $t0, $t1 CS2710 Computer Organization

Fully worked register example C/Java code: f = (g + h) - (i + j); assume f, …, j in $s0, …, $s4 Equivalent MIPS assembly code: add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s0, $t0, $t1 CS2710 Computer Organization

The University of Adelaide, School of Computer Science 10 April 2017 Memory Operands Main memory used for composite data Arrays, structures, dynamic data To apply arithmetic operations Load values from memory into registers Store result from register to memory Memory is byte addressed Each address identifies an 8-bit byte Words are aligned in memory Address must be a multiple of 4 MIPS is Big Endian Most-significant byte at least address of a word c.f. Little Endian: least-significant byte at least address Chapter 2 — Instructions: Language of the Computer — 18 Chapter 2 — Instructions: Language of the Computer

Registers can only hold a small amount of data Registers can only hold a small amount of data. The rest is kept in main memory. 0x00000009 0x00000008 0x00000007 0x00000006 0x00000005 Byte 3 MIPS Memory is organized and accessed in a linear array of (billions of) bytes Recall: a byte is 8 bits Each byte has a unique address In MIPS, a word is 4 bytes In MIPS, words must start at addresses that are multiples of 4 Byte 4 Byte 1 Word 2 Byte 2 Byte 3 0x00000004 0x00000003 0x00000002 0x00000001 0x00000000 Byte 4 Byte 1 Word 1 Byte 2 Why does the byte-ordering appear backward??? Byte 3 Byte 4 CS-280 Dr. Mark L. Hornick

CS2710 Computer Organization MIPS is “big-endian” Consider the integer value 305,419,896 With hexadecimal and binary representations as: 0x 12 34 56 78 0b 00010010001101000101011001111000 byte4 byte3 byte2 byte1 Note: sometimes the bytes are numbered from 0-3 instead of from 1-4 Bit 0 Bit 31 CS2710 Computer Organization

In a big-endian representation, the least significant byte has a higher address than the most significant byte 0x00000009 0x00000008 0x00000007 0x00000006 0x00000005 Byte 3 In our example of 305,419,896 (0x12345678), the bytes of the 32-bit word representing that value would appear as shown at the right The address of the entire word is the address of the most signficant byte (MSB) – in this case the byte 0x12 Thus, the address of 0x12345678 is 0x00000000 This is where the word starts in memory in this example Byte 4 Byte 1 (LSB) Word 2 Byte 2 Byte 3 0x00000004 0x00000003 0x00000002 0x00000001 0x00000000 Byte 4 (MSB) 0x78 0x12345678 0x56 0x34 0x12 CS-280 Dr. Mark L. Hornick

Memory Operand Example 1 The University of Adelaide, School of Computer Science 10 April 2017 Memory Operand Example 1 Java/C code: g = h + A[8]; g in $s1, h in $s2, base address of A in $s3 Compiled MIPS code: Index 8 requires offset of 32 4 bytes per word! lw $t0, 32($s3) # load word add $s1, $s2, $t0 base register offset Chapter 2 — Instructions: Language of the Computer — 22 Chapter 2 — Instructions: Language of the Computer

Memory Operand Example 2 The University of Adelaide, School of Computer Science 10 April 2017 Memory Operand Example 2 Java/C code: A[12] = h + A[8]; Assume h in $s2, base address of A in $s3 Compiled MIPS code: Index 8 requires offset of 32 lw $t0, 32($s3) # load word add $t0, $s2, $t0 sw $t0, 48($s3) # store word Chapter 2 — Instructions: Language of the Computer — 23 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 10 April 2017 Registers vs. Memory Registers are much faster to access than memory Operating on memory data requires loads and stores 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! Chapter 2 — Instructions: Language of the Computer — 24 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 10 April 2017 Immediate Operands Constant data specified in an instruction: addi $s3, $s3, 4 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 Chapter 2 — Instructions: Language of the Computer — 25 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 10 April 2017 The Constant Zero MIPS register 0 ($zero) is the constant 0 Cannot be overwritten Useful for common operations E.g., move values between registers add $t2, $s1, $zero # t2 = s1+0 = s1 Note: Some other instruction sets have a dedicated MOV instruction to perform this operation. Why did MIPS decide not to have a MOV? Chapter 2 — Instructions: Language of the Computer — 26 Chapter 2 — Instructions: Language of the Computer