- Количество слайдов: 37
Computer Science Theory & Introduction Week 1 Lecture Material Penn State University CMPSC 201 – C++ Programming for Engineers Original class notes from Dough Hogan, http: //www. personal. psu. edu/djh 300/index. htm
Hardware vs. Software Hardware : physical components of a computer system essentially, things you can touch input, output, storage devices Software : A collection of computer programs and its related data that provides the instructions telling a computer what to do! In contrast to hardware, software "cannot be touched“! 0 s and 1 s : Owing to its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by all modern computers.
Hardware vs. Software Application Software System Software Hardware
Components of a Computer Central processing unit (CPU) Memory Input devices Output devices Storage devices
Central Processing Unit (CPU) Basic job: handle processing of instructions What’s an instruction? Two parts: Control Unit (CU) Arithmetic and Logic Unit (ALU)
The ALU Built up from digital logic gates AND OR NOT most primitive level
Memory Holds programs that are currently running and the data being used by those programs. Two categories: Read-only memory (ROM) can only read data Random-access memory (RAM) can read and write information primary storage - computer’s main memory volatile
Sequential Access vs. Random Access Sequential Access: must access each location in memory in order Random Access: can access memory locations using addresses, in any order Track 1 Track 2 Speed implications?
Memory: sizes base unit: 1 bit = binary digit, 0 or 1 8 bits = 1 byte (B) 1000 bytes ≈ 1 kilobyte (KB) 1000 KB ≈ 1, 000 B ≈ 1 megabyte (MB) 1000 MB ≈ 1, 000, 000 B ≈ 1 gigabyte (GB)
Storage Devices Floppy disk 3. 5 inches, 1. 44 MB Hard disk typically sizes in GB Compact disc (CD) 650 -700 MB CD-ROM: read-only memory CD-R: recordable CD-RW: rewritable
More Storage Devices Digital Versitale/Video Disc (DVD) 4. 7 GB Flash drives varies Zip disks and tape drives varies
Input Devices mouse keyboard scanner camera microphone
Output Devices monitor cathode ray tube (CRT) liquid crystal display (LCD) printer speakers
Software Overview System software Controls basic operations of computer The operating system manages memory, files, application software File management tasks – deleting, etc.
Software Overview Application software Not essential to system running Enables you to perform specific tasks Ex: Office software Web browsers Media players Games
Algorithms and Languages
Algorithms An algorithm is a set of instructions to solve a problem. Think recipes! Many algorithms may solve the same problem! How do we choose between them? The answer is that: Different Algorithms differ in the time and the space they take to run! we choose the most efficient algorithm according to our resources! (space and time) Example: You may have a lot of memory and your only concern is how fast the program runs, or the other way around.
Programming Paradigms/Models Procedural Programming: specify steps to solve problem, use procedures to implement those steps Procedures are called methods in C++ Object-Oriented Programming (OOP): create objects to model real-world entities. e. g. an employee object As in real world each object has its own Information: (represented by data types) Behaviors: (implemented by methods/procedures) Objects can interact, as they do in real world Event-Driven Programming: create methods that respond to events like mouse clicks, key presses, etc. Others: Functional, logic, etc.
Compiling Process Code in machine language Source Code (C++) compiler Object Code Compiler is a software that transforms a source code written in one programming language into a program in another language (usually machine language, a language than can be executed by CPU) linker Object Code from Libraries Executable Program
linker : A program that takes two or more object files generated by a compiler and combines them into a single executable program. Source Code (C++) compiler Object Code linker Object Code from Libraries Executable Program
Library has been complied before! , it won’t need to be compiled every time. Source Code (C++) compiler Source Code of library (C++) Object Code linker compiler Object Code from Libraries Executable Program
Compiled vs. Interpreted Languages Compiled Language Requires software called a compiler to translate the program into (usually) an executable program with machine language Syntax errors will be found during compilation code will be syntax-error free while executing (running) Examples: C, C++, Pascal, FORTRAN, BASIC Interpreted Language Requires software called an interpreter to run the code Code is checked for errors as it runs (if erroneous code: does the best it can…) Examples: HTML, Java. Script, PHP
Errors Syntax Errors Much like using incorrect punctuation or grammar in English Compiler reports syntax errors; program won’t run until they’re resolved Logic Errors Program doesn’t solve the problem correctly It May be correct syntactically, but it is not doing what is supposed to do (according to specification of program)! Runtime Errors that occur while the program is running, e. g. problems accessing memory, divide by zero
Abstraction is a fundamental concept to CS Principle of ignoring details , so that by focusing on more general concepts we are able to use complex devices Focusing on the WHAT, rather than HOW Example: Abstract of a paper! Example: Your report template!
Levels of Abstraction 0. Digital Logic 1. Machine Language A system of instructions, that are executable directly by the CPU. Every CPU has an instruction set architecture (ISA) of its own! 2. Operating System 3. Low-Level Language Low refers to small or no amount of abstraction from machine language. e. g. Assembly language 4. High-Level Language High refers to strong abstraction from the details of the CPU design Uses natural language elements, thus it’s easier to understand 5. Application Software
Binary Numbers Use two symbols: 0 and 1 to represents numbers Base 2 Compare with decimal number system Uses symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to represents numbers Base 10 At the lowest level of abstraction, everything in a computer is expressed in binary.
Binary Numbers, ctd. 0 1 10 11 100 101 110 111 0 1 2 3 4 5 6 7 1000 1001 1010 1011 1100 1101 1110 1111 10000 8 9 10 11 12 13 14 15 16
Binary Numbers, ctd. 11 + 1 ___________ 100 0 1 10 11 100 101 110 111 0 1 2 3 4 5 6 7 1000 + 1 ___________ 1001 1000 1001 1010 1011 1100 1101 1110 1111 10000 8 9 10 11 12 13 14 15 16
Convert Vs. Decimal
Other Number Systems Any positive integer could be the base of a number system. (Big topic in number theory. ) Others used in computer science: Octal: Base 8 Hexadecimal: Base 16 New symbols A, B, C, D, E, F
Example of machine language instructions At the lowest level of abstraction, everything in a computer is expressed in binary. This is an example of an ‘Add’ instruction: 0000001 00010 00110 00000 100000 Couple of more examples of machine language instructions: 100011 01000 0000100 000010 00000 1000000
Hello World Example in Assembly Language. model small. stack. data message db "Hello world, I'm learning Assembly !!!", "$". code main proc mov ax, seg message mov ds, ax mov ah, 09 lea dx, message int 21 h mov ax, 4 c 00 h int 21 h min endp enad main
ASCII Every character on a computer -- letters, digits, symbols, etc. -- is represented by a numeric code behind the scenes. ASCII is a character-encoding scheme based on the ordering of the English alphabet Short for American Standard Code for Information Interchange. Most modern character-encoding schemes are based on ASCII, though they support many more characters than does ASCII. We’ll learn more in lab…
# Transistors on a Processor 1971 2, 250 8008 1972 2, 500 8080 1974 5, 000 8086 1978 29, 000 1982 120, 000 1985 275, 000 486 DX Yates, Daniel S. , and David S. Moore and Daren S. Starnes. The Practice of Statistics. 2 nd Ed. New York: Freeman, 2003. 4004 386 Data from Section 4. 1 of : Number of Transistors 286 Data for Intel processors: Date 1989 1, 180, 000 Pentium 1993 3, 100, 000 Pentium II 1997 7, 500, 000 Pentium III 1999 24, 000 Pentium 4 2000 42, 000
A Graphical View Pay attention to the units on the axes… Graph from Intel's web site (http: //www. intel. com/technology/mooreslaw/index. htm); Retrieved 9/24/2006
Moore’s Law Prediction from Gordon Moore of Intel in 1965. Implication: The speed of processors doubles roughly every 12 to 18 months. Can this go on forever?