Computer Architecture Instruction Set Architecture

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

Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
The University of Adelaide, School of Computer Science
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
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.
Assembly Language II CPSC 321 Andreas Klappenecker.
MIPS Architecture CPSC 321 Computer Architecture Andreas Klappenecker.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
MIPS Instruction Set Advantages
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization Rabie A. Ramadan Lecture 3.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Chapter 2 Instructions: Language of the Computer.
Computer Architecture & Operations I
Lecture 5: Procedure Calls
Computer Architecture Instruction Set Architecture
MIPS Instruction Set Advantages
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
William Stallings Computer Organization and Architecture 8th Edition
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
ECE/CS 552: Instruction Sets – MIPS
The University of Adelaide, School of Computer Science
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
Lecture 5: Procedure Calls
Chapter 2 Instructions: Language of the Computer part 2
The University of Adelaide, School of Computer Science
Computer Instructions
3.
COMS 361 Computer Organization
Lecture 6: Assembly Programs
Systems Architecture I
Computer Architecture
Presentation transcript:

Computer Architecture Instruction Set Architecture Lynn Choi Korea University

Machine Language Programming language Translator High-level programming languages Procedural (imperative) languages: C, PASCAL, FORTRAN Object-oriented languages: C++, Objective-C, Java Functional (declarative) languages: Lisp, Scheme Multiple paradigms (hybrid): Python, C# Assembly programming languages: symbolic machine languages Machine languages: binary (1’s and 0’s), IA32, IA64, ARM, MIPS, PowerPC Translator Compiler: translate a high-level language program into a machine language program Assembler: translate an assembly language program into a machine language program A part of a compiler Interpreter: translate and execute programs directly JVM(Java virtual machine): translate/execute Java bytecode to native machine instructions cf. Java compiler translate Java program to Java bytecode

Compiler Compiler Compiler What qualities do you want in a compiler? A program that translates a source program (written in language A) into an equivalent target program (written in language B) Source program Usually written in high-level programming languages (called source language) such as C, C++, Java, FORTRAN, Python Target program Usually written in machine languages (called target language) such as x86, Alpha, MIPS, SPARC, or ARM instructions What qualities do you want in a compiler? Generate correct code Target code runs fast Compiler runs fast Support for separate compilation, good diagnostics for errors Source Program Compiler Target Program

Compilation Process Preprocessor Compiler Assembler Linker Source program Expands macros and header files into the source program Preprocessor Expanded Source Program Compiler Assembly Program Assembler Relocatable code (object file) Libraries, other relocatable object files Linker Target program (executable file)

Compiler Phases Source Program Lexical Analyzer Syntax Analyzer Object Lexical Analyzer Syntax Analyzer Intermediate Code Generator Code Optimizer Target Tokens Tree I.C. O.C. Front-End : language dependent I.C. : Intermediate Code O.C. : Optimized Code Back-End : machine dependent

Machine State ISA defines machine states and instructions Registers CPU internal storage to store data fetched from memory Can be read or written in a single cycle Arithmetic and logic operations are usually performed on registers MIPS ISA has 32 32-bit registers: Each register consists of 32 flip-flops Top level of the memory hierarchy Registers <-> caches <-> memory <-> hard disk Registers are visible to programmers and maintained by programmers Caches are invisible to programmers and maintained by HW Memory A large, single dimensional array, starting at address 0 To access a data item in memory, an instruction must supply an address. Store programs (which contains both instructions and data) To transfer data, use load (memory to register) and store (register to memory) instructions

Data Size & Alignment Data size Byte addressability Alignment Word : the default data size for computation 32b for 32b ISA, 64b for 64b ISA Double word: 64b data, Half word: 16b data, Byte: 8b data Load/store instructions can designate data sizes transferred: ldw, lddw, ldhw, ldb Byte addressability Each byte has an address Alignment Objects must start at addresses that are multiple of their size Object addressed Aligned addresses Misaligned addresses Byte 0, 1, 2, 3, 4, 5, 6, 7 Never Half Word 0, 2, 4, 6 1, 3, 5, 7 Word 0, 4 1, 2, 3, 5, 6, 7 Double Word 0 1, 2, 3, 4, 5, 6, 7

Machine Instruction EX) ADD, MULT, LOAD, STORE, JUMP Opcode : specifies the operation to be performed EX) ADD, MULT, LOAD, STORE, JUMP Operands : specifies the location of data Source operands (input data) Destination operands (output data) The location can be Memory operand specified by a memory address : EX) 8(R2), x1004F Register operand specified by a register number : R1

Instruction Types Arithmetic and logic instructions Performs actual computation on operands EX) ADD, MULT, XOR, SHIFT, FDIVIDE, FADD Data transfer instructions (memory instructions) Move data from memory to registers (LOAD) or vice versa (STORE) Input/Output instructions are usually implemented by memory instructions (memory-mapped IO) IO devices are mapped to memory address space Control transfer instructions (branch instructions) Change the program control flow (i.e. change the PC) Determine the address of the next instruction to be fetched Program Counter (PC): A special register that holds the address of the next instruction to execute Unconditional jumps and conditional branches Direct branches and indirect branches EX) JUMP, CALL, RETURN, BEQ

MIPS Instruction Format 6 5 5 5 5 6 Op: Opcode, basic operation of the instruction Rs: 1st source register Rt: 2nd source register Rd: destination register shamt: shift amount funct: function code, the specific variant of the opcode Used for arithmetic/logic instructions Rs: base register Address: +/- 215 bytes offset (or also called displacement) Used for loads/stores and conditional branches op rs rt rd shamt funct R-type 6 5 5 16 I-type op rs rt address

MIPS Addressing Modes Register addressing Base addressing Address is in a register jr $ra (indirect branches) Base addressing Address is the sum of a register (base register) and a constant (offset) ldw $s0, 100($s1) Immediate addressing For constant operand (immediate operand) add $t1, $t2, 3 PC-relative addressing Address is the sum of PC and a constant (offset) beq $s0, $s1, L1 Pseudodirect addressing Address is the 26 bit offset concatenated with the upper bits of PC j L1

MIPS Instruction formats Arithmetic instructions Data transfer, conditional branch, immediate format instructions Jump instructions R-type 6 5 5 5 5 6 op rs rt rd shamt funct I-type 6 5 5 16 op rs rt address/immediate J-type 6 26 op address

MIPS Instruction Example: R-format add $8,$9,$10 Decimal number per field representation: 9 10 8 32 Binary number per field representation: hex 000000 01001 01010 01000 100000 00000 hex representation: 012A 4020hex Elsevier Inc. All rights reserved decimal representation: 19,546,144ten Called a Machine Language Instruction

MIPS Instruction Opcode Table Elsevier Inc. All rights reserved

MIPS Instruction Examples Elsevier Inc. All rights reserved

The University of Adelaide, School of Computer Science If Statement 16 June 2018 C code: if (i==j) f = g+h; else f = g-h; f, g, h, i, j in $s0, $s1, $s2, $s3, $s4 Compiled MIPS code: bne $s3, $s4, Else add $s0, $s1, $s2 j Exit Else: sub $s0, $s1, $s2 Exit: … Assembler calculates addresses Chapter 2 — Instructions: Language of the Computer — 16 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science Counted Loop 16 June 2018 C code: sum = 0; for (i=1; i <= 10; i++) sum = sum + i; sum in $s3, i in $t1 Compiled MIPS code: addi $s3, $zero, 0 addi $t1, $zero, 1 loop: add $s3, $s3, $t1 addi $t1, $t1, 1 sle $t2, $t1, 10 bne $t2, $zero, loop Chapter 2 — Instructions: Language of the Computer — 17 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science While Loop 16 June 2018 C code: while (save[i] == k) i += 1; i in $s3, k in $s5, address of save in $s6 Compiled MIPS code: Loop: sll $t1, $s3, 2 add $t1, $t1, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, 1 j Loop Exit: … Chapter 2 — Instructions: Language of the Computer — 18 Chapter 2 — Instructions: Language of the Computer

Procedure Call & Return Steps of procedure call & return Place parameters in a place where the callee can access $a0 - $a3: four argument registers Transfer control to the callee jal callee_address : jump and link instruction Put return address (PC+4) in $ra and jump to the callee Acquire the storage (stack frame) needed for the callee Perform the desired task Place the result value in a place where the caller can access $v0 - $v1: two value registers to return values Return control to the caller jr $ra

Stack Stack frame (activation record) of a procedure Store variables local to a procedure Procedure’s saved registers Arguments, return address, saved registers, local variables Stack pointer : point to the top of the stack Frame pointer : point to the bottom of the top stack frame Elsevier Inc. All rights reserved

MIPS Memory Allocation Elsevier Inc. All rights reserved

MIPS Register Convention Elsevier Inc. All rights reserved

MIPS Example : Procedure int leaf_example (int g, int h, int i, int j) { int f; f = (g + h) – ( i + j); return f;} Assembly code leaf_example: sub $sp, $sp, 8 sw $t1, 4($sp) # save register $t1, $t0 onto stack sw $t0, 0($sp) add $t0, $a0, $a1 # $t0 = g + h add $t1, $a2, $a3 # $t1 = i + j sub $v0, $t0, $t1 # $v0 = (g + h) – (i + j) lw $t0, 0($sp) # restore $t0, $t1 for caller lw $t1, 4($sp) add $sp, $sp, 8 jr $ra Elsevier Inc. All rights reserved

MIPS Example : Recursion int fact (int n) { if (n <2) return 1; else return n * fact (n – 1); } Assembly code fact: addi $sp, $sp, -8 # adjust stack pointer for 2 items sw $ra, 4($sp) # save return address and argument n sw $a0, 0($sp) slt $t0, $a0, 2 # if n < 2, then $t0 = 1 beq $t0, $zero, L1 # if n >=2, go to L1 addi $v0, $zero, 1 # return 1 addi $sp, $sp, 8 # pop 2 items off stack jr $ra L1: addi $a0, $a0, -1 # $a0 = n - 1 jal fact # call fact(n – 1) lw $a0, 0($sp) # pop argument n and return address lw $ra, 4($sp) addi $sp, $sp, 8 # pop 2 items off stack mul $v0, $a0, $v0 # return n * fact(n – 1)