High level vs Low Level. What is a Computer Program? What does gcc do for you? Program = Instructions + Data. Basic Computer Organization

Similar documents
Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

Assembler. Building a Modern Computer From First Principles.

News. Recap: While Loop Example. Reading. Recap: Do Loop Example. Recap: For Loop Example

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Lecture 3: Computer Arithmetic: Multiplication and Division

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

Brave New World Pseudocode Reference

CMPS 10 Introduction to Computer Science Lecture Notes

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface.

Overview. CSC 2400: Computer Systems. Pointers in C. Pointers - Variables that hold memory addresses - Using pointers to do call-by-reference in C

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

Virtual Memory. Background. No. 10. Virtual Memory: concept. Logical Memory Space (review) Demand Paging(1) Virtual Memory

Parallel matrix-vector multiplication

Esc101 Lecture 1 st April, 2008 Generating Permutation

Introduction to Programming. Lecture 13: Container data structures. Container data structures. Topics for this lecture. A basic issue with containers

CSCI 104 Sorting Algorithms. Mark Redekopp David Kempe

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Intro. Iterators. 1. Access

Data Representation in Digital Design, a Single Conversion Equation and a Formal Languages Approach

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Cache Memories. Lecture 14 Cache Memories. Inserting an L1 Cache Between the CPU and Main Memory. General Org of a Cache Memory

The Greedy Method. Outline and Reading. Change Money Problem. Greedy Algorithms. Applications of the Greedy Strategy. The Greedy Method Technique

Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

Conditional Speculative Decimal Addition*

3D vector computer graphics

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

Mathematics 256 a course in differential equations for engineering students

ELEC 377 Operating Systems. Week 6 Class 3

CS221: Algorithms and Data Structures. Priority Queues and Heaps. Alan J. Hu (Borrowing slides from Steve Wolfman)

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

RADIX-10 PARALLEL DECIMAL MULTIPLIER

VRT012 User s guide V0.1. Address: Žirmūnų g. 27, Vilnius LT-09105, Phone: (370-5) , Fax: (370-5) ,

Lobachevsky State University of Nizhni Novgorod. Polyhedron. Quick Start Guide

Active Contours/Snakes

Efficient Distributed File System (EDFS)

TECHNIQUE OF FORMATION HOMOGENEOUS SAMPLE SAME OBJECTS. Muradaliyev A.Z.

Nachos Project 3. Speaker: Sheng-Wei Cheng 2010/12/16

Motivation. EE 457 Unit 4. Throughput vs. Latency. Performance Depends on View Point?! Computer System Performance. An individual user wants to:

Giving credit where credit is due

Machine Learning: Algorithms and Applications

4/11/17. Agenda. Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Storage Management.

Notes on Organizing Java Code: Packages, Visibility, and Scope

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

Image Representation & Visualization Basic Imaging Algorithms Shape Representation and Analysis. outline

Q.f f fractional bits : [-2 b-1 / 2 f, (2 b-1-1) / 2 f ] e.g. Q.15 Needs f+1 bits at least, b>f Resolution 2 -f

Support Vector Machines

Sorting Review. Sorting. Comparison Sorting. CSE 680 Prof. Roger Crawfis. Assumptions

Course Introduction. Algorithm 8/31/2017. COSC 320 Advanced Data Structures and Algorithms. COSC 320 Advanced Data Structures and Algorithms

Today s Outline. Sorting: The Big Picture. Why Sort? Selection Sort: Idea. Insertion Sort: Idea. Sorting Chapter 7 in Weiss.

Area Efficient Self Timed Adders For Low Power Applications in VLSI

Array transposition in CUDA shared memory

Memory and I/O Organization

Insertion Sort. Divide and Conquer Sorting. Divide and Conquer. Mergesort. Mergesort Example. Auxiliary Array

MATHEMATICS FORM ONE SCHEME OF WORK 2004

Computer models of motion: Iterative calculations

Lecture 5: Multilayer Perceptrons

An Optimal Algorithm for Prufer Codes *

CS1100 Introduction to Programming

Report on On-line Graph Coloring

2D Raster Graphics. Integer grid Sequential (left-right, top-down) scan. Computer Graphics

Outline. Digital Systems. C.2: Gates, Truth Tables and Logic Equations. Truth Tables. Logic Gates 9/8/2011

Pass by Reference vs. Pass by Value

Performance Evaluation of Information Retrieval Systems

Agenda & Reading. Simple If. Decision-Making Statements. COMPSCI 280 S1C Applications Programming. Programming Fundamentals

Outline. CIS 110: Introduction to Computer Programming. Review: Interactive Sum. More Cumulative Algorithms. Interactive Sum Trace (2)

AP PHYSICS B 2008 SCORING GUIDELINES

This chapter discusses aspects of heat conduction. The equilibrium heat conduction on a rod. In this chapter, Arrays will be discussed.

Load Balancing for Hex-Cell Interconnection Network

Improved Symoblic Simulation By Dynamic Funtional Space Partitioning

CS240: Programming in C. Lecture 12: Polymorphic Sorting

Sorting. Sorting. Why Sort? Consistent Ordering

CPE 628 Chapter 2 Design for Testability. Dr. Rhonda Kay Gaede UAH. UAH Chapter Introduction

Sorting: The Big Picture. The steps of QuickSort. QuickSort Example. QuickSort Example. QuickSort Example. Recursive Quicksort

Problem Set 3 Solutions

5.1 The ISR: Overvieui. chapter

Setup and Use. Version 3.7 2/1/2014

IP Camera Configuration Software Instruction Manual

AADL : about scheduling analysis

Design and Analysis of Algorithms

ON SOME ENTERTAINING APPLICATIONS OF THE CONCEPT OF SET IN COMPUTER SCIENCE COURSE

The AVL Balance Condition. CSE 326: Data Structures. AVL Trees. The AVL Tree Data Structure. Is this an AVL Tree? Height of an AVL Tree

Random Kernel Perceptron on ATTiny2313 Microcontroller

On Some Entertaining Applications of the Concept of Set in Computer Science Course

FPGA IMPLEMENTATION OF RADIX-10 PARALLEL DECIMAL MULTIPLIER

Storage Binding in RTL synthesis

Using Delayed Addition Techniques to Accelerate Integer and Floating-Point Calculations in Configurable Hardware

VISUAL SELECTION OF SURFACE FEATURES DURING THEIR GEOMETRIC SIMULATION WITH THE HELP OF COMPUTER TECHNOLOGIES

12/2/2009. Announcements. Parametric / Non-parametric. Case-Based Reasoning. Nearest-Neighbor on Images. Nearest-Neighbor Classification

Outline. Discriminative classifiers for image recognition. Where in the World? A nearest neighbor recognition example 4/14/2011. CS 376 Lecture 22 1

LLVM passes and Intro to Loop Transformation Frameworks

Specifications in 2001

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

BITPLANE AG IMARISCOLOC. Operating Instructions. Manual Version 1.0 January the image revolution starts here.

CHAPTER 4. Applications of Boolean Algebra/ Minterm and Maxterm Expansions

Algorithm To Convert A Decimal To A Fraction

Fitting: Deformable contours April 26 th, 2018

Programming in Fortran 90 : 2017/2018

CE 221 Data Structures and Algorithms

Life Tables (Times) Summary. Sample StatFolio: lifetable times.sgp

Transcription:

What s a Computer Program? Descrpton of algorthms and data structures to acheve a specfc ojectve Could e done n any language, even a natural language lke Englsh Programmng language: A Standard notaton for wrtng programs Eamples: C, Java, Intel assemly language An etreme eample: Machne language Hence the need for program translators Eample: gcc Hgh level vs Low Level Englsh: To calculate the smple nterest, multply the prncpal amount y the rate of nterest y the numer of years C: W = X * Y * Z; Even etter C statement: SmpIeInterest = Prncpal * Rate * Years; 6 Hgh level vs Low Level Machne language: (transformed to a human readale form) movss (%rp), %mm movss y(%rp), %mm mulss %mm, %mm movss z(%rp), %mm mulss %mm, %mm movss %mm, w(%rp) C program s made up of statements Machne language program s made up of machne nstructons What does gcc do for you? % gcc hello.c hello.c source : Program that you wrote n the C language and typed nto the fle hello.c gcc a.out eecutale : Fle generated y gcc. The a.out fle contans an equvalent program n machne language that can e eecuted on a computer system 9 Basc Computer Organzaton Processor or CPU Memory The `rans of the computer system Program = Instructons + Data We wll net learn more aout data I/O Bus I/O I/O Where thngs are rememered program, data

There are dfferent knds of data How does one pece of data dffer from another? Constant vs Varale Basc vs Structured Of dfferent types Character Integer (unsgned, sgned) Real Others (oolean, comple, ) Data dfferng n ther lfetmes Lfetme: Interval etween tme of creaton and end of estence How long can the lfetme of a datum e? We wll consder 3 possle lfetmes 3 Program Data: Dfferent Lfetmes.. Lfetme = Eecuton tme of program Intalzed/unntalzed data Must e ndcated n eecutale fle The space n memory for all of ths data can e assgned when program eecuton starts (Statc Allocaton) Program Data: Dfferent Lfetmes.. Lfetme = Eecuton tme of program. Lfetme = Tme etween eplct creaton of data & eplct deleton of data Dynamc memory allocaton In C you create new data usng a functon lke malloc() The memory space for ths data s managed dynamcally when the malloc/free s eecuted (Heap allocaton) 4 5 Program Data: Dfferent Lfetmes... Lfetme = Eecuton tme of program. Lfetme = Tme etween eplct creaton of data & eplct deleton of data 3. Lfetme = Durng eecuton of a functon (.e., tme etween functon call and return) Local varales, parameters of the functon The memory space for ths data s assgned when the functon s called and reclamed on return from the functon (Stack allocaton) Stack: Lke a ple of ooks on a tale 6 Stack allocated: Functon Local Varales When the program starts eecutng Top of Stack Ponter Local Varales of man What f man() then calls functon func()? 7

Stack allocated: Functon Local Varales. Whle eecutng n functon func() Stack allocated: Functon Local Varales.. Eecutng n man() once agan Local varales of func Local Local Varales of of man Top of Stack Ponter Local Varales of man Top of Stack Ponter What happens on return from the call to func()? 8 9 Recurson vs Iteraton Eample: Compute N!, N > j fact N { nt N, fact, j; j++) for (fact=, j=; j <= N; fact = fact * j; J= J= J=98 J=99 N J= nt factoral (nt j) { f (j == ) return(); )); vod man() { nt N; return (j * factoral(j- factoral(n); Durng program eecuton Code (machne language program) Data (ntalzed and unntalzed) Code and Data don t change n sze whle the program s eecutng Heap (for dynamcally allocated data) Stack (for functon local varales) Heap and Stack change n sze as program eecutes Code Intalzed Unntalzed Heap Stack Dgtal Computers As opposed to mechancal computers or analog computers Baage s Analytcal Engne Mechancal computers used mechancal parts lke gears and levers to calculate wkpeda 3

Analog Computer Dgtal Computers.. In current dgtal computers, values vary etween dscrete values and hgh and low Volts and 3 Volts Analog computers used contnuously varyng quanttes lke voltage In dgtal computers, dscretely varyng values are used nstead http://userwww.sfsu.edu/~hl/c.heath.analog.html 5 Dgtal Crcuts Electrcal crcuts n whch voltages only take on a dscrete numer of values There are dgtal crcuts that can do calculatons, others that can e used to rememer values, etc 6 Eample: Bnary Addton Bnary: Base numer system You can generalze the decmal numer system, whch uses dgts (,,,9) to work wth any rad or ase ( d n n nd n... ddd ) ten d n dn... d d d n d Bnary dgts (called ts): and ( n n nn... ) two n n... n Eample: Decmal 47 s Bnary Bnary Addton.. t adder A crcut that can add one t to another t The dfferent cases + + + + = = =??? = = = = One t adder has nputs and outputs a t adder s c Bnary Addton.. t adder A crcut that can add one t value (a a ) to another t value ( ) s s Full t adder a a + s s s a s c t adder Ths dea can e etended to desgn a 3 t adder or a 64 t adder a 4

How s Data Represented? On a dgtal computer Bnary Base numer system Two values: and Bt (Notaton: ); Byte (Notaton: B) 8 ts Other notaton: K, M, G, T, P etc K:, M:, G: 3, etc G =,73,74,84 GB of RAM, TB hard dsk drve Character Data Typcally represented usng the ASCII code ASCII: Amercan Standard Code for Informaton Interchange Each character s represented y a unque 8 t ASCII code word Eample: a s represented y, s represented y 3 3 How s Data Represented? Character data: ASCII code Integer data In computer systems, you usually fnd support for oth sgned ntegers and unsgned ntegers e.g., C programmng nt ; Can take +ve or -ve whole numer values unsgned nt y; Can take on +ve whole numer values Unsgned Integer Data Representaton: Bnary numer system ( n n nn... ) two n n... n e.g., Decmal s represented as.e. n 6 ts n 3 ts 3 33 Asde: << C << operator e.g., y = << 3; Left Shft y 3 ts Shfts each t to the left y 3 ts The 3 ts on the etreme left go away 3 Zero s come n at the rght etreme end e.g., n 8 ts, << 3 s Clam: Shftng an unsgned nt left y one t s the same as multplcaton y Qualfcaton: If the product can e computed.e., all of the ts that go away are Zero Asde: <<.. Proof: Consder n t value I = ( nn... ) Shfted left y t and n- = we get ( nn3... ) n I n two two 34 5

Sgned Integer Data s Complement Representaton The n t quantty n n... represents the sgned nteger value n n n least sgnfcant t Eample: In 8 ts -8 + 64 + 3 + 6 + + 3 s represented as -3 s represented as 36 How s Data Represented? Character data: ASCII code Sgned Integer data: s complement Real data 37 Real data Real numers: ponts on the nfntely long real numer lne There are an nfntely many ponts etween any two ponts on the real numer lne Real Data: Floatng Pont Representaton IEEE Floatng Pont Standard (IEEE 754) 3 t value wth 3 components ( s, e, f ). s ( t sgn). e (8 t eponent) 3. f (3 t fracton) represents the value s ( ). f e7 38 39 Eample: IEEE Sngle Float Consder the decmal value.5 Equal to. n nary. s ( ). f s:, e: 6, f: e7 In 3 ts, 4 Basc Computer Organzaton Man parts of a computer system: Processor: Eecutes programs Man memory: Holds program and data I/O devces: For communcaton wth outsde Machne nstructon: Descrpton of prmtve operaton that machne hardware s ale to eecute e.g. ADD these two ntegers Instructon Set: Complete specfcaton of all the knds of nstructons that the processor hardware was ult to eecute 4 6

Basc Computer Organzaton Processor or CPU Memory Bus I/O I/O I/O 4 Asde: Aout Memory What s memory? Devces that can rememer thngs There are dfferent knds of memory n a computer system Some rememer y the state an electrcal crcut s n e.g., SRAM Others rememer y the amount of electrcal charge stored n a capactor e.g., DRAM Memory Yet others rememer y magnetc or optcal propertes e.g., Hard dsk drve/mag Tape, CD/DVD They can vary sustantally n ther speed and capacty 43 Man Memory. Holds nstructons and data Vew t as a sequence of fed szed locatons, each referred to y a unque memory address In many computers, the sze of each memory locaton s Byte,73,74,83 (f memory s of sze GB) 8 ts 3 Man Memory.. Values that occupy more than 8 ts would occupy more than one, neghourng memory locatons e.g., 3 t sgned nteger would occupy 4 neghourng memory locatons, maye as shown 3,73,74,83 8 ts 44 + + +3 char A[4] A[] A[] A[] A[3] Data Structures: Arrays rows char B[4][] columns B[][] B[][] B[][] B[][] B[][] B[][] 3 B[3][] B[3][] + + +3 +4 +5 +6 +7 B[][] B[][] B[][] B[][] B[][] B[][] B[3][] B[3][] struct node { char data; Data Structures: Lnked Lsts struct node *net; / a ponter: 3 ts n sze struct node *head; / a character: 8 ts n sze / a ponter: 3 ts n sze / n memory at address < z z > 7