CSE 2021: Computer Organization

Similar documents
Architecture II. Computer Systems Laboratory Sungkyunkwan University

Machine Instructions - II. Hwansoo Han

Thomas Polzer Institut für Technische Informatik

MIPS Instruction Set Architecture (2)

CSE 2021: Computer Organization

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

Chapter 2. Instructions: Language of the Computer

CS3350B Computer Architecture MIPS Procedures and Compilation

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

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

Control Instructions

COMPUTER ORGANIZATION AND DESIGN

Two processors sharing an area of memory. P1 writes, then P2 reads Data race if P1 and P2 don t synchronize. Result depends of order of accesses

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

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

Previously. CSE 2021: Computer Organization. Memory Organization. The Load/Store Family (1) 5/26/2011. Used to transfer data to/from DRAM.

Computer Architecture

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

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

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

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

Computer Architecture Computer Science & Engineering. Chapter 2. Instructions: Language of the Computer BK TP.HCM

Chapter 2. Instruction Set. The MIPS Instruction Set. Arithmetic Operations. Instructions: Language of the Computer

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

MIPS (SPIM) Assembler Syntax

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

Reduced Instruction Set Computer (RISC)

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

Chapter 2. Instructions: Language of the Computer

LECTURE 2: INSTRUCTIONS

Chapter 2. Instructions: Language of the Computer

Assembler. Lecture 8 CS301

Lecture 4: MIPS Instruction Set

CENG3420 Lecture 03 Review

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

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

Reduced Instruction Set Computer (RISC)

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

Systems Architecture I

Instruction Set. The MIPS Instruction Set. Chapter 2

ECE 15B COMPUTER ORGANIZATION

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Instruction Set Architecture

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

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 2. Instructions: Language of the Computer

MIPS Reference Guide

Instructors: Randy H. Katz David A. PaKerson hkp://inst.eecs.berkeley.edu/~cs61c/fa10. Fall Lecture #11. Agenda

Course Administration

Computer Architecture

Chapter 2: Instructions:

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

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

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

Lecture 5: Procedure Calls

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

Computer Organization and Design

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

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Instructions: Language of the Computer. Euiseong Seo Computer Systems Laboratory Sungkyunkwan University

Computer Architecture. MIPS Instruction Set Architecture

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

Lectures 3-4: MIPS instructions

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

Lecture 6: Assembly Programs

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

From Code to Program: CALL Con'nued (Linking, and Loading)

Assembler. #13 Running a Program II

ECE 15B Computer Organization Spring 2011

Computer Architecture. The Language of the Machine

Lec 13: Linking and Memory. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

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

Chapter 2. Instructions: Language of the Computer. Baback Izadi ECE Department

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

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

CS3350B Computer Architecture MIPS Instruction Representation

Course Administration

Communicating with People (2.8)

CS 61c: Great Ideas in Computer Architecture

Course Administration

EEC 581 Computer Architecture Lecture 1 Review MIPS

Topic Notes: MIPS Instruction Set Architecture

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

MIPS Instruction Set

ECE Exam I February 19 th, :00 pm 4:25pm

CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions

UCB CS61C : Machine Structures

Lecture 7: Examples, MARS, Arithmetic

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

MIPS Assembly Language. Today s Lecture

Flow of Control -- Conditional branch instructions

CENG3420 L03: Instruction Set Architecture

Computer Architecture

CS/COE1541: Introduction to Computer Architecture

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

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

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Transcription:

CSE 2021: Computer Organization Lecture-5 Code Translation-3 Heap, Storage options, Addressing modes, Concurrent data access, Linking & loading Shakil M. Khan (adapted from Prof. Roumani)

So Far Registers ($s0 - $s7, $t0 - $t9, $zero) Arithmetic and logical instructions (add, sub, mult, div, slt, sll, srl, sra, the i/u/v suffix) Jump and branch (j, beq, bne) Load and store (lb, lh, lw, sb, sw, sh, the u suffix) I/O (syscall) MIPS instruction formats (R-type, I-type, J-type) Static attributes and.data (directives:.byte,.half,.word,.ascii,.asciiz,.space),.text Procedures (jal, jr, $v0 - $v1, $a0 - $a3, $ra) Stack ($sp, $fp) lui, mfhi, mflo, Some pseudo-instructions (la, mul, ) CSE-2021 June-2-2011 2

Assumptions for Phase III None! We need to be able to accommodate non-static Attributes (storage allocated on the heap) Multi-Class Applications (multiple classes loaded and linked) CSE-2021 June-2-2011 3

Global Symbols.globl sym declares that label sym is global can be referenced from other files Example (see sum.s and summain.s) File 1: File 2:.globl sum.globl x.text.data main: #$s0=input an integer # add $a0, $0, $s0 x:.ascii Result: jal sum.text #print x sum: #$v0=sum 0 to $a0 #print $v0 jr $ra CSE-2021 June-2-2011 4

Heap Usage To allocate four bytes on the heap:.text main: addi $a0, $0, 4 addi $v0, $0, 9 syscall sw $s0, 0($v0) # heap store lw $s0, 0($v0) # heap load CSE-2021 June-2-2011 5

Memory Map 0000 0000 (4MB) 0040 0000 (252MB) 1000 0000 (64KB) 1001 0000 reserved.text.data heap $gp $sp 7fff fffc stack $fp CSE-2021 June-2-2011 6

Review: Data Storage Options Registers Data segment Stack Heap DRAM Disk / SSD CSE-2021 June-2-2011 7

Exercise For each data storage option, determine: its latency, i.e. time to retrieve one byte (in seconds) its typical size (in bytes) the lifetime of its content what is it used for in Java / C how to allocate storage in it how to transfer data to/from it CSE-2021 June-2-2011 8

Data Storage Options: Registers Very Fast (latency ~1 nsec) DRAM ~100 nsec disk ~1 msec = 1,000,000 nsec Very few general-purpose registers (< 25) Each has a bit width of 32 or 64 Must spill to DRAM on method calls Suitable for storing intermediate work only All computations in RISC operate on registers only (e.g. you cannot add to memory directly) all programs must therefore use registers after fetching data from DRAM CSE-2021 June-2-2011 9

Data Storage Options: Data Segment AKA Static Storage Implemented via.data Size fixed at program time cannot grow/shrink Lifetime = duration of Program Java: used for static attributes C: used for static variables and fixed-size arrays/strings CSE-2021 June-2-2011 10

Data Storage Options: Stack Segment AKA Automatic Storage Implemented via $sp, $fp Size can change but only in a LIFO manner Lifetime = duration of Method Used for local variables, ones defined within methods in Java or functions in C CSE-2021 June-2-2011 11

Data Storage Options: Heap Segment AKA Dynamic Storage Implemented via syscall#9 Size can change in any manner Lifetime is program-controlled Java: used for objects (via new) and is automanaged by a garbage collector C: used for any data (via malloc) and is manually managed (mismanaged ) by the programmer CSE-2021 June-2-2011 12

Data Storage Options: Disk AKA Secondary Storage Implemented via syscalls (open, read, write) Size is practically unlimited Lifetime is permanent (beyond program) *Used to persist data in files *Data is fetched from files to DRAM via syscalls and then to registers via loads *The reverse (register-to-dram) is done via stores CSE-2021 June-2-2011 13

MIPS Addressing Modes (branches) Addressing in branches why absolute addressing fails? compression #1: count in words compression #2: PC-relative (thus signed) Last resort: reverse the condition (see branching far away) op rs rt constant or address 6 bits 5 bits 5 bits 16 bits CSE-2021 June-2-2011 14

Branch Addressing Branch instructions specify opcode, two registers, target address Most branch targets are near branch forward or backward op rs rt constant or address 6 bits 5 bits 5 bits 16 bits PC-relative addressing target address = PC + offset 4 PC already incremented by 4 by this time CSE-2021 June-2-2011 15

Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites the code as a jump Example beq $s0,$s1, L1 bne $s0,$s1, L2 j L1 L2: CSE-2021 June-2-2011 16

Encoding Jumps Addressing in jumps why absolute addressing fails? compression #1: count in words compression #2: invent a new format (J-type) compression #3: borrow 4-bits from PC limit on code size 26 bits = 64 MW = 256 MB op address 6 bits 26 bits CSE-2021 June-2-2011 17

Jump Addressing Jump (j and jal) targets could be anywhere in text segment encode full address in instruction op address 6 bits 26 bits (Pseudo)Direct jump addressing target address = PC[31 28] : (address 4) CSE-2021 June-2-2011 18

Target Addressing Example Loop code example assume Loop at location 80000 Loop: sll $t1, $s3, 2 80000 0 0 19 9 2 0 add $t1, $t1, $s6 80004 0 9 22 9 0 32 lw $t0, 0($t1) 80008 35 9 8 0 bne $t0, $s5, Exit 80012 5 8 21 2 addi $s3, $s3, 1 80016 8 19 19 1 j Loop 80020 2 20000 Exit: 80024 CSE-2021 June-2-2011 19

Addressing Mode Summary CSE-2021 June-2-2011 20

Concurrent Data Access: The Dining Philosophers wikipedia.org CSE-2021 June-2-2011 21

Concurrent Data Access: The Problems Deadlock Livelock resource starvation Two processors sharing an area of memory P1 writes, then P2 reads data race if P1 and P2 don t synchronize result depends of order of accesses CSE-2021 June-2-2011 22

Synchronization The Solution Use a semaphore to place a lock Hardware support required need an atomic read/write memory operation no other access to the location allowed between the read and write Could be a single instruction e.g., atomic swap of register memory or an atomic pair of instructions Cannot read and write in the same cycle in MIPS so use a linked load with a conditional store CSE-2021 June-2-2011 23

Synchronization in MIPS Load linked: ll rt, offset(rs) Store conditional: sc rt, offset(rs) succeeds if location not changed since the ll returns 1 in rt fails if location is changed returns 0 in rt Example: atomic swap (to test/set lock variable) try: add $t0,$zero,$s4 #copy exchange value ll $t1,0($s1) #load linked sc $t0,0($s1) #store conditional beq $t0,$zero,try #branch store fails add $s4,$zero,$t1 #put load value in $s4 CSE-2021 June-2-2011 24

Example # thread-safe (synchronized) balance withdrawal.text # $s0 = address of a/c balance # $s1 = withdrawal amount try: ll $t1, 0($s0) # load link the balance sub $t1, $t1, $s1 # adjust it sc $t1, 0($s0) # store it back conditionally beq $t0, $0, try # did it work? CSE-2021 June-2-2011 25

Translation and Startup Many compilers produce object modules directly Static linking CSE-2021 June-2-2011 26

Producing an Object Module Assembler (or compiler) translates program into machine instructions Provides information for building a complete program from the pieces Header: described contents of object module Text segment: translated instructions Static data segment: data allocated for the life of the program Relocation info: for contents that depend on absolute location of loaded program Symbol table: global definitions and external refs Debug info: for associating with source code CSE-2021 June-2-2011 27

Linking Object Modules Why linker (AKA link editor)? Steps for linker 1. merges segments 2. resolve labels (determine their addresses) 3. patch location-dependent and external refs Produces an executable image same format as object files, but contains no unresolved references CSE-2021 June-2-2011 28

Loading a Program Load from image file on disk into memory 1. read header to determine segment sizes 2. create virtual address space 3. copy text and initialized data into memory or set page table entries so they can be faulted in 4. set up arguments on stack 5. initialize registers (including $sp, $fp, $gp) 6. jump to startup routine copies arguments to $a0, and calls main when main returns, do exit syscall CSE-2021 June-2-2011 29

Dynamic Linking Only link/load library procedure when it is called requires procedure code to be relocatable avoids image bloat caused by static linking of all (transitively) referenced libraries automatically picks up new library versions CSE-2021 June-2-2011 30

Lazy Linkage Indirection table Stub: Loads routine ID, Jump to linker/loader Linker/loader code Dynamically mapped code CSE-2021 June-2-2011 31

Starting Java Applications Simple portable instruction set for the JVM Compiles bytecodes of hot methods into native code for host machine Interprets bytecodes CSE-2021 June-2-2011 32