Week 1 Lecture Material Penn State University CMPSC 201 – C++ Programming for Engineers Original class notes from Dough Hogan, Computer Science Theory & Introduction
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“! 0s and 1s : 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 Speed implications? Track 1 Track 2
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,000 B ≈ 1 megabyte (MB) 1000 MB ≈ 1,000,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) 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 Source Code (C++) Object Code Executable Program Object Code from Libraries compilerlinker 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) Code in machine language
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++) Object Code Executable Program Object Code from Libraries compilerlinker
Library has been complied before!, it won’t need to be compiled every time. Object Code from Libraries Source Code of library (C++) compiler
Compiled vs. Interpreted Languages 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, JavaScript, PHP 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
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 Errors that occur while the program is running, e.g. problems accessing memory, divide by zero
Abstraction 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
Binary Numbers, ctd _____________________ _____________________
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: Couple of more examples of machine language instructions:
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 21h mov ax,4c00h int 21h 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…
Moor’s Law
# Transistors on a Processor ProcessorDateNumber of Transistors , , , , , , DX19891,180,000 Pentium19933,100,000 Pentium II19977,500,000 Pentium III199924,000,000 Pentium ,000,000 Data for Intel processors: Data from Section 4.1 of : Yates, Daniel S., and David S. Moore and Daren S. Starnes. The Practice of Statistics. 2nd Ed. New York: Freeman, 2003.
A Graphical View Graph from Intel's web site ( Retrieved 9/24/2006http:// Pay attention to the units on the axes…
Moore’s Law Prediction from Gordon Moore of Intel in Implication: The speed of processors doubles roughly every 12 to 18 months. Can this go on forever?