Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Structured Programming in C Welcome to CPSC 206.

Similar presentations


Presentation on theme: "1 Structured Programming in C Welcome to CPSC 206."— Presentation transcript:

1 1 Structured Programming in C Welcome to CPSC 206

2 2 Lecture Information http://people.cs.tamu.edu/ychen/Teaching/CPSC206

3 3 Lecture Topics: 0. Introduction to Computer Science 1. Overview of CCh 1, 2 2. Flow of control and functionsCh 3, 4 3. Character processing & fundamental data typesCh 5, 6 4. File I/O Ch 13 5. Pointers, Arrays, and StringsCh 8, 9, 10 6. Structures, and linked listsCh 12 Features of C: 7. Enumeration type and storage classesCh 7, 8 8. RecursionCh 11

4 4 Introduction to Computer Science CONCEPTS AND PROGRAMMING

5 5 Introduction to Computer Science — Outline  Part I: an overview of computer science.  Part II: computer hardware and software.  Part III: computer languages.

6 6 Part I: An Overview of Computer Science  What is Computer Science?

7 7 What is Computer Science? Formal Definition The systematic study of computing systems and computation. The body of knowledge resulting from this discipline contains theories for understanding computing systems and methods; design methodology, algorithms, and tools; methods for the testing of concepts; methods of analysis and verification; and knowledge representation and implementation. http://www.hpcc.gov/pubs/blue94/section.6.html Definition provided by the National Coordination Office for Information Technology Research and Development (NCO/IT R&D) Part I: An Overview of Computer Science

8 8 What is Computer Science? A simple answer The study of how to solve problems with computers. Part I: An Overview of Computer Science What are the specific research areas of computer science?

9 9 What is Computer Science? 1, Design and Build a computer  Operating Systems  Example of OS: Windows, Unix  CPSC 410 Architecture, Electrical Engineering  ELEN 220, Intro Digital Design  CPSC 321, 462, 469 A computer with user-friendly services 2, Are services provided on the computer so we can use the computer efficiently? Part I: An Overview of Computer Science

10 10 Windows or Unix What is Computer Science? Computability theory 3, Given a problem, can we use a computer to solve the problem? 4, How to solve it? yes Algorithm Design  CPSC311, Analysis of algorithm Part I: An Overview of Computer ScienceProblem: …………

11 11 What is Computer Science? Programming Language  CPSC111: Computer Science Concepts and Programming Compilers  CPSC434: Compiler Design 5, Given the algorithm,  How can we translate the algorithm into instructions which computer can understand.  That is, how can we communicate with the computer? Part I: An Overview of Computer Science

12 12 Windows or Unix What is Computer Science? AlgorithmAlgorithm 3, Given a problem, check whether a computer can solve it. 4, Design an algorithm to solve it. yes Part I: An Overview of Computer Science 1, Design and Build a computer. 2, Friendly services are provided. Problem: ………… 5, Communicate with the computer. Instructions: 0101110011011101 1110111011110100 0010111011010101 0001011101111011 …………… Architecture Operating System Computability theory Algorithm Design Programming Language, Compiler What else?

13 13 What is Computer Science? Complexity theory  CPSC311: Analysis of algorithm  CPSC627:Theory of Computability 6, Given a solution for a problem,  Is the solution correct?  Is it efficient?  Is it optimal? Part I: An Overview of Computer Science

14 14 What is Computer Science? Artificial Intelligence  CPSC320: Artificial Intelligence 7, Given a problem, can the computer finds the solution 8, I have developed a solution for a problem. Human-computer Interaction  CPSC436: Computer- Human Interaction  Is my solution easy for people to use? Part I: An Overview of Computer Science automatically automatically?

15 15 What is Computer Science? Software Engineering  CPSC 431: Software Engineering 9, I want to develop a BIG software, how can I handle a complicated situation? 10, Internet, Networks, Mobile Ad Hoc Networks ……  How to develop network applications? Networking, Parallel and Distributed Systems.  CPSC 463: Networks and Distributed Processing. Part I: An Overview of Computer Science

16 16 Summary of Part I Part I: An Overview of Computer Science Architecture Operating System Computability theory Algorithm Design Compiler Complexity theory Artificial Intelligence Human-computer Interaction Software Engineering Parallel and Distributed Systems. Programming Language Networking The study of how to solve problems with computers.

17 17 Introduction to Computer Science — Outline  Part I: an overview of computer science.  Part II: computer hardware and software.  Part III: computer languages.

18 18 Part II: Computer Hardware and Software Outline:  The development of modern computer systems.  Computer organization.  Solving problems on computers.  Programming and software engineering.

19 19 The development of modern computer systems  Early electronic computers  Mainframes  Time sharing  Microcomputers  Networked computing Check course website for details. Part II: Computer Hardware and Software http://students.cs.tamu.edu/ychen/Teaching/CPSC206/index.htm#_Notes

20 20 Part II: Computer Hardware and Software Outline:  The development of modern computer systems.  Computer organization.  Solving problems on computers.  Programming and software engineering.

21 21 Computer Organization Part II: Computer Hardware and Software — Computer Organization

22 22 O utline Part II: Computer Hardware and Software — Computer Organization CPU Memory Hard Driver Input/Output (1) How data is represented in computer? Secondary Storage

23 23 Outline Part II: Computer Hardware and Software — Computer Organization  Data representation  Main Memory  Central Processing Unit (CPU)  Secondary Storage  Input / Output

24 24 Data representation — What is data? Part II: Computer Hardware and Software — Computer Organization The information which a computer processes data values  Individual data values may represent  numbers,  alphabetic characters, or  other coded information.

25 25 Data representation — What is data?  Instructions of computer programs are also data?  Yes.  The instructions must be stored in the computer’s memory before they are able to be processed. Part II: Computer Hardware and Software — Computer Organization The information which a computer processes

26 26 Data representation — How data is stored and processed? binary 01 All data is stored and processed in binary form, that is, as a series of 0s and 1s. bit Each binary digit is called a bit. 01010011000110111101  The smallest unit of information which can be stored in the computer. Part II: Computer Hardware and Software — Computer Organization

27 27 Data representation — How data is stored and processed? A computer word defines the number of bits which can be stored in a memory cell  The length of a word might be different on different computer. 11100010110001010011000110111101 Bits are grouped into longer units known as bytes to hold more meaningful data. 1 byte = 8 bits Part II: Computer Hardware and Software — Computer Organization 1 2 3 4

28 28 2020 21212 2323 2424 2525 2626 2727 Data representation — Binary Number Counting in decimal Counting in binary Binary Numbers 10 0 10 1 10 2 10 3 (1*10 3 ) + (9*10 2 ) + (8*10 1 ) + (9*10 0 ) = 1989 10011001 (1*2 7 ) + (0*2 6 ) + (0*2 5 ) + (1*2 4 ) + (1*2 3 ) + (0*2 2 ) + (0*2 1 ) +(1*2 0 ) = 153 in base10 1989 One thousand, nine hundred and eighty nine eight times ten Part II: Computer Hardware and Software — Computer Organization 7 6 5 4 3 2 1 0

29 29 Data representation — Binary Number, Examples Part II: Computer Hardware and Software — Computer Organization (1*2 4 ) Try converting these numbers from binary to decimal: 10 111 = (1*2 1 ) + (0*2 0 ) = 2+0 = 2 =(1*2 2 ) + (1*2 1 ) + (1*2 0 ) = 4+2+1=7 11110= = 16+8+4+2+0 = 30 +(1*2 1 )+(1*2 3 )+ (1*2 2 )+(0*2 0 )

30 30 Data representation — How data is represented in binary form? Number: +6, - 6, +99  Value of a number Part II: Computer Hardware and Software — Computer Organization  Sign of a number

31 31 Data representation — How data is processed? Number: sign The sign bit represents the sign of the number. e.g.  0 implies a positive number  1 implies a negative number 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 +6 - 6 Part II: Computer Hardware and Software — Computer Organization 6 sign bit magnitude bits In a binary representation, the leftmost bit is a sign bit followed by the magnitude bits.

32 32 Data representation — How data is processed? Number — Examples: Represented in 16-bit memory, Part II: Computer Hardware and Software — Computer Organization 01111111 1111111111111111 Represented in 8-bit memory, 127 32767 +127 -32767

33 33 000000001111111 Data representation — How data is processed? Number — Examples: Part II: Computer Hardware and Software — Computer Organization 01111111 +127 Represented in 8-bit How to represent +127 in 16-bit memory? 0 sign bit magnitude bits (15 bits) 00000001111111= 0*2 14 +0*2 13 +0*2 12 +0*2 11 +0*2 10 +0*2 9 + 0*2 8 +0*2 7 +1*2 6 +1*2 5 + 1*2 4 +1*2 3 +1*2 2 +1*2 1 + 1*2 0 = 127

34 34 Data representation — How data is processed? Number — Examples: Represented in 16-bit Part II: Computer Hardware and Software — Computer Organization 1111111111111111 -32767 How to represent -32767 in 8-bit memory? Answer: We cannot do it since 32767 cannot be represented by a 7-bit binary number. What is the maximum value can be represented by a 7-bit binary number? 1111111= 1*2 6 +1*2 5 + 1*2 4 +1*2 3 +1*2 2 +1*2 1 + 1*2 0 = 127

35 35 Data representation — How data is processed? Characters: ASCII coding systems ASCII – American Standard Code for Information Interchange Each character is represented in a 7-bit format: Hello  1001000 1000101 1001100 1001100 1001111 Example: Part II: Computer Hardware and Software — Computer Organization H  0 1 0 0 1 0 0 0 E  0 1 0 0 0 1 0 1 L  0 1 0 0 1 1 0 0 o  0 1 0 0 1 1 1 1

36 36 Outline Part II: Computer Hardware and Software — Computer Organization  Data representation  Main Memory  Central Processing Unit (CPU)  Secondary Storage  Input / Output

37 37 Main memory  What is Main memory  It is part of a computer’s electronic circuitry which holds the binary data which the computer’s program will process. Part II: Computer Hardware and Software — Computer Organization

38 38 Main memory Part II: Computer Hardware and Software — Computer Organization  Memory is divided into cells.  Each cell is assigned a specific address, from 0 to the maximum size of the computer’s memory capacity.

39 39 Main memory (cont.) size  The size of a computer’s memory is the number of the addressable cells it contains. Bit1 Byte8 bits Kilobyte210 bytes1,000 Megabyte210 kilobyte 1,000,000 Gigabyte210 megabyte 1,000,000,000 Terrabyte210 Gigabytes trillion e.g. A 256K bytes of memory have 256*1024=262,144 bytes. Part II: Computer Hardware and Software — Computer Organization

40 40 Main memory — Features of Memory  Random Access  High-speed  Read/Write Capability  Volatility  Memory loses its contents when the power is turned off. Part II: Computer Hardware and Software — Computer Organization

41 41 Outline Part II: Computer Hardware and Software — Computer Organization  Data representation  Main Memory  Central Processing Unit (CPU)  Secondary Storage  Input / Output

42 42 CPU: Central Processing Unit  CPU is the heart of a computer.  Control unit Control and coordinate the computer’s operations.  Arithmetic/Logic Unit (ALU) performs all arithmetic computations and logic operations. Part II: Computer Hardware and Software — Computer Organization

43 43 Control unit  Program execution 1. Each computer has a unique instruction set determined by the designers of its architecture. Each instruction includes a code that specifies the operation to be performed, and the memory address of the data value to be acted on. Part II: Computer Hardware and Software — Computer Organization

44 44 Control unit  Program execution 2. All the operations of a computer are directed by a set of instructions, known as a program, which is loaded in the computer’s main memory during execution. Part II: Computer Hardware and Software — Computer Organization

45 45 Control unit  Program execution 3. The control unit locates the appropriate instructions, controls their sequencing, and executes them by activating appropriate circuitry. Part II: Computer Hardware and Software — Computer Organization

46 46 Control unit (cont.)  Program Counter (PC)  contains the memory address of the instruction that is currently being executed.  Instruction counter (IC)  contains the instruction currently being processed. Part II: Computer Hardware and Software — Computer Organization

47 47 Control unit (cont.)  Hardware characteristics  CPU synchronizes its operations by the regular pulses emitted by an electronic device called a clock.  The speed of a computer can be quoted as:  Clock speed, e.g. 100MHz means 100 million cycles per second.  MIPS, a million instructions per second, or the unit of time it takes to execute one instruction. Part II: Computer Hardware and Software — Computer Organization

48 48 Arithmetic/Logical Unit  ALU performs all arithmetic computations and logical operations.  Arithmetic - Add, subtract, multiply, divide exponentiation etc.  Logical -Testing for relationships. A<B;name == “mary”; c>=10; possible Answers? True or False Part II: Computer Hardware and Software — Computer Organization The ALU contains special memory cells, known as registers, in which the arithmetic is carried out.

49 49 reads the individual program instructions from main memory. Executes one instruction at a time until completion Fetch - Decode - Execute The machine cycle algorithm is continuously repeated until program termination. CPU Machine Cycle Part II: Computer Hardware and Software — Computer Organization

50 50 Fetch:  Retrieve the next instruction from memory [where the command is located (address) in program counter]  Update the program counter to the address of the next instruction.  The instruction just Fetched is placed in register. Part II: Computer Hardware and Software — Computer Organization

51 51 Decode the Bit pattern in the register Having decoded the instruction, the control unit enters the execute phase. It activates the correct circuitry to perform the requested task. Decode: Execute: Part II: Computer Hardware and Software — Computer Organization

52 52  If the instruction is a load from memory, the Control Unit causes the load to occur.  If the instruction is for an arithmetic operation, the control unit activates the appropriate circuitry in the ALU with the correct input stored in registers.  When the instruction has been executed, the control unit again begins the machine cycle with the Fetch cmd (the address of the next cmd is in the program counter). Part II: Computer Hardware and Software — Computer Organization

53 53 Secondary Storage Mass storage devices Sequential storage: tape. Random storage: floppy disk, zip disk, CD- ROM, etc. Indirect addressing. Static storage. Slower speed. Part II: Computer Hardware and Software — Computer Organization

54 54 User Input / Output  Input  Devices: keyboard, mouse, light pen, etc.  Data translation: interfaces.  Output  Devices: computer screen, printer (dot matrix, ink jet or laser), etc.  Data translation: buffers. Part II: Computer Hardware and Software — Computer Organization

55 55 IPOS Cycle I - Input Part II: Computer Hardware and Software — Computer Organization Data/ Program Memory P - Process CPU Program Output O - OutputS - S econdary Storage Medium Data/Program


Download ppt "1 Structured Programming in C Welcome to CPSC 206."

Similar presentations


Ads by Google