1 / 71

Introduction

Introduction. Contents. Computers Programming. What is a Computer ?. We live in a world of electronic devices Not all of these are computers What makes a computer different from the other devices?. What is a Computer ?. A computer can Receive data from the outside world

masako
Download Presentation

Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction

  2. Contents • Computers • Programming

  3. What is a Computer ? • We live in a world of electronic devices • Not all of these are computers • What makes a computer different from the other devices?

  4. What is a Computer ? • A computer can • Receive data from the outside world • Process this data in some way to compute results • Store data for varying periods of time • Output results to the outside world • Allow the user to have the computer remember a series of operations to perform so that the same thing can be done again

  5. How does this differ from a calculator? • A calculator can • Accept input from the world via the keys • Perform calculations by pressing keys • Store values in its memory • Output results • A calculator cannot • Store a series of operations to be performed later

  6. What Does a Computer Do? Whatever I tell it to do • I say: Add 2 and 3 and show me the result • Computer says: 5 • I say: Multiply that result by 7 and show me the result • Computer says: 35 • I say: Show me the home page of the Marmara CE department • Computer says:

  7. What’s Going On?

  8. Read an input and memorize it • Read another input and memorize it • Add the inputs, display and memorize result • Read input and memorize it • Multiply input with previous result • and display the result The Ghost in the Machine • Hardware does the work • Programmer writes a program for the machine • Program tells hardware what to do at each step

  9. WHAT is PROGRAMMING??scheduling or performing a task or / and eventWHAT is COMPUTER PROGRAMMING??creating a sequence of steps for a computer to follow in performing a task

  10. WHAT is a PROGRAMMING LANGUAGE ? A set of rules, symbols, and special words used to construct a computer program

  11. Where do you see programming in real life? • Short answer: all over the place!

  12. What’s a Computer? A computer is a device that processes data and computes results under the direction ofa program Notice that the computer does nothing by itself It is told what to do by a program (software) Program refers to a specific set of instructions given to the computer to accomplish a specific task Compute the sum of N numbers Find min/max of N numbers Sort numbers Compute average grade of a class Find the shortest path between 2 cities …… 12

  13. Hardware (Computer Architecture) Central Processing Unit (CPU) Executes instructions Random Access Memory (RAM) Stores volatile data Input/Output (I/O) Devices Keyboard, Monitor, Disk, Mouse, Network Card, … Used to input/output data Memory CPU Input/Output (I/O) Devices System Bus Relevant Courses 1. Computer Architecture 2. Microprocessors 13

  14. Memory Divided into logical units of the same size called a byte Each byte is made up of 8 consecutive binary digits or bits Each bit is in one of two states OFF: 0 ON: 1 Each byte has a unique address First byte has address ”0 ” 0 0 1 0 1 0 1 1 0 0 1 0 0 0 1 0 0 1 1 0 1 0 0 1 1 1 1 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 1 1 1 1 1 0 Most-significant bit Least-significant bit Address Byte 0 Byte 1 Byte 2 Byte 3 Byte N-1 1 byte 14

  15. More on Memory Bytes are also grouped in larger chunks According to Intel convention 1 byte : 8 consecutive bits 1 word : 2 consecutive bytes 1 longword: 4 consecutive bytes 1 quadword: 8 consecutive bytes 1 octaword: 16 consecutive bytes 15

  16. More on Memory Size of a memory is measured in bytes However the memory size is usually expressed in larger units 1 Kilobyte (KB) = 1024 bytes = 2^10 ~ 10^3 bytes 1 Megabyte (MB) = 1024*1024 = 2^20 ~ 10^6 bytes 1 Gigabyte (GB) = 2^30 ~ 10^9 bytes 1 Terrabyte (TB) = 2^40 ~ 10^12 bytes 1 Petabyte (PT) = 2^50 ~ 10^15 bytes Maximum memory size depends on the architecture 32-bit system  max. memory size: 2^32=4GB 64-bit system  max. memory size: 2^64bytes 16

  17. Central Processing Unit (CPU) Brain of the computer Executes instructions specified by the program ALU/ FPU Control Unit Registers IP System Bus Bus Interface • CPU consists of several subunits • Control Unit + Instruction Pointer (IP) • Fetch & Decode Instructions • Arithmetic Logic Unit • Perform arithmetic and logical operations • Add, subtract, multiply, divide, compare, shift,… • Registers • Hold temporary data needed by the instruction 17

  18. Basic Operation of the Computer loop: Fetch the next instruction from memory Decode the instruction Interpret what the instruction means Fetch the operands (if necessary) Fetch the operands from memory to CPU registers Execute the instruction Perform what the instruction is telling us to do (add, subtract, multiply, divide, …) Store the result back to memory (if necessary) repeat 18

  19. Why do we need programming? • You think: “Hello World” • The computer would think: H E L L O [space] W O R L D 01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100 This notation is simple or….. what? What do you think? What is your prefer?

  20. Nobody else wants to, either.

  21. What’s the other choice? • Instead, we use “programming languages” to talk to the computer. • Just like other languages, you express ideas in different ways when using different programming languages. • What are some foreign languages you can think of?

  22. There are lots of programming languages, too. • Here are some you might have heard of: Basic, Java, Javascript, Logo. • Here are some you probably haven’t heard of before now: C++, Perl, Scheme, C#, Python, Lisp, Cobol, Fortran, Pascal, SQL, Haskell, J2EE, Maple, PHP, Ruby, Ubercode.

  23. Program (Software) Conceptually a program is a step-by-step solution to a problem Also named an algorithm A well-defined computational procedure that takes some values (data) as input and produces some results as output ALGORITHM Input (DATA) Output (Results) 23

  24. Algorithms (source : wikipedia) • In mathematics, computing, linguistics and related disciplines, an algorithm is a procedure (a finite set of well-defined instructions) for accomplishing some task which, given an initial state, will terminate in a defined end-state. • Algorithms are essential to the way computers process information, because a computer program is essentially an algorithm that tells the computer what specific steps to perform (in what specific order) in order to carry out a specified task, such as calculating employees’ paychecks or printing students’ report cards.Thus, an algorithm can be considered to be any sequence of operations which can be performed by a Turing-Complete system.

  25. More on Software IP Algorithm Steps DATA Step1 Step2 Relevant Courses 1. Intro to Comp. Eng. 2. Data Structures 3. Databases 4. Algorithms Step3 Step4 Step5 StepN Pseudo-code (Human-readable) Relevant Courses 1. Introduction to Computer Engineering 2. C Programming 3. Visual Programming (C#) 4. Object Oriented Programming (Adv. OO Concepts and Java) 5. Advanced Programming Techniques (Advanced Java) 25

  26. Expressing the Algorithms • A “Standard” way of describing an algorithm must exist if we expect our solution to be understood by others easily • There are two standards in programming: • NATURAL LANGUAGE • PSEUDOCODE • FLOWCHARTS • PROGRAMMING LANGUAGE

  27. Natural Language • "...prose to describe an algorithm, ignoring the implementation details. At this level we do not need to mention how the machine manages its tape or head“ • In the philosophy of language, a natural language (or ordinary language) is a language that is spoken, written, or signed (visually or tactilely) by humans for general-purpose communication, as distinguished from such constructs as computer-programming languages or the "languages" used in the study of formal logic, especially mathematical logic.

  28. Pseudo Code • “Pseudo” means “pretend” or “false” • Pseudo Code is pretend or false computer code; generic English-like terms that are somewhat like computer code • Pseudo Code is not as standardized as flowcharts, and does not facilitate the breaking down of problems as well as a flowchart does

  29. Pseudocode (wikipedia) • Pseudocode (derived from pseudo and code) is a compact and informal high-level description of a computer programmingalgorithm that uses the structural conventions of programming languages, but omits detailed subroutines, variable declarations or language-specific syntax. The programming language is augmented with natural language descriptions of the details, where convenient.

  30. Flowcharts • A Flowchart is a Visual Representation of an algorithm • A Flowchart uses easy-to-understand symbols to represent actions on data and the flow of data • Flowcharts aid in breaking down a problem into simple steps

  31. Example of flowcharts

  32. Example : One of the simplest algorithms is to find the largest number in an (unsorted) list of numbers. The solution necessarily requires looking at every number in the list, but only once at each. From this follows a simple algorithm, which can be stated in a high-level description English prose, as:

  33. Natural language: Assume the first item is largest. Look at each of the remaining items in the list and if it is larger than the largest item so far, make a note of it. The last noted item is the largest in the list when the process is complete.

  34. (Quasi-) Formal description: Written in prose but much closer to the high-level language of a computer program, the following is the more formal coding of the algorithm in pseudo code : AlgorithmLargestNumber Input: A non-empty list of numbers L. Output: The largest number in the list L. largest ← L0 for eachitemin the list L≥1, do if the item > largest, then largest ← the itemreturnlargest • "←" is a loose shorthand for "changes to". For instance, "largest ← item" means that the value of largest changes to the value of item. • "return" terminates the algorithm and outputs the value that follows.

  35. Example Program: Compute the sum, product and avg of 2 numbers, a & b IP IP IP IP IP IP IP IP DATA ALGORITHM a  10 b  40 sum  a+b product  a*b avg  sum/2 print sum print product print avg a 10 ? ? b 40 ? sum 50 ? product ? 400 avg 25 ? SCREEN 50 400 25 35

  36. Assignment ! • Make an algorithms in high level language, pseudo code and flowchart for • Computing factorial (N!) • Finding roots of ax2 + bx + c = 0

  37. Operating System Is a layer of software that exports an easy-to-use interface to program the hardware User Programs P1 P2 Pn System call API Operating System (Windows, Linux, Solaris, …) Hardware API Hardware • User programs make use of the hardware through the services provided by the OS • Thus OS makes life easier for user programs • Relevant course: Operating Systems 37

  38. From Algorithm to 0s and 1s Although we showed the instructions stored in memory in pseudo-code (human readable form), what is really stored is 0s and 1s Remember a computer only understands 0s and 1s This means that we need tools that would help us convert the program from human-readable form to the machine-readable form called the machine language These tools are called system software tools 38

  39. System Software Components We have several system software components to make programming the computer easy High-level Programming Languages (C, C++, Java, C#, ..) Compiler Converts your programs implemented in high-level language to assembly language, which are mnemonic codes that correspond one-to-one with machine language Assembler Converts programs implemented in assembly language to machine language, which are binary number codes understood by a specific CPU Linker Combines several object files together into an executable Loader + Operating System Loads your program into memory for execution 39

  40. What Programs Look Like ;Read first input and store it in variable a ; Read second input and store it in variable b ; Add the values of a and b and store the result in variable c ; Read third input and store it in variable d ; Multiply the values of c and d and store the result in variable e ;Display the value of variable e read (a) read (b) c = a + b read (d) e = d * c print (e) • The computer takes each of these instructions and executes it

  41. out = in1 + in2 Computer’s Job: Compute Outputs from Inputs CPU 2 in1 5 out 3 in2

  42. Computer’s Job: Read/Write Variables From/To Memory a 2 c = a + b c 5 b CPU 3 2 5 3 Memory c = a + b

  43. Computer’s Job: Input and Output read (a) read (b) a 2 c = a + b print (c) c b CPU 2 Memory 2 read (a)

  44. Computer’s Job: Input and Output read (a) read (b) a 2 c = a + b print (c) c b CPU 3 3 Memory 3 read (b)

  45. Computer’s Job: Input and Output read (a) read (b) a 2 c = a + b print (c) c 5 b CPU 3 2 5 3 Memory c = a + b

  46. Computer’s Job: Input and Output read (a) read (b) a 2 c = a + b print (c) c 5 b CPU 3 5 Memory 5 5 print (c)

  47. Computer’s Job: Representing and Translating Information • How does computer understand “a”, “b”, “4”, etc. • i.e. data values? • How does computer understand “read (a)”; that it should add its inputs, when to read from memory, when to take next step etc. • i.e. control • Answer: Everything is represented as 1’s and 0’s • Computer only sees 1’s and 0’s • All data values, instructions etc. are encoded as combinations of 1’s and 0’s

  48. The World of 1’s and 0’s 0010 00000 00001 c = a + b 00010 0101 10011 CPU 0011 0010 0101 11111 0011 Memory 010111001

  49. WHAT is LANGUAGE ?

  50. Programmability • The ability to store a series of operations and perform them later is called programmability • It is programmability which distinguishes a computer from a calculator • Programmability allows • Long sequences of operations to be stored • These sequences to be repeated any time • Conditional logic to be included

More Related