View
221
Download
0
Tags:
Embed Size (px)
Citation preview
CS101 - Introduction To Computer Concepts 1
Purpose of Computer programs
• The purpose of writing a program is to solve a problem, perform a repetitious task or manage data
• The general steps in computer programming and general problem solving are:
– Understand the problem or task requirements
– Break down the problem or requirements into manageable pieces
– Design a solution addressing all aspects of the task
– Consider alternatives to the solution and refine it
– Implement the solution
– Test the solution and fix any problems that exist
CS101 - Introduction To Computer Concepts 2
Computer Program Life Cycle
CS101 - Introduction To Computer Concepts 3
• Software projects can fail because the developer didn't really understand the problem or task at hand
• The software development did not gather all the details and cases relevant to the task
• The complexity of the system caused the solution to become confusing and disconnected.
• Software development team did not use the correct technology tools
Common Program Development Problems
CS101 - Introduction To Computer Concepts 4
Computer Program Structure Chart
CS101 - Introduction To Computer Concepts 5
• Flowchart
Computer Program Flow Chart
CS101 - Introduction To Computer Concepts 6
• Computer– Performs computations and makes logical decisions– Millions / billions times faster than human beings
• Computer programs– Sets of instructions by which a computer processes data
• Hardware– Physical devices of computer system
• Software– Programs that run on computers
2003 Prentice Hall, Inc. All rights reserved. (modified by Evan Korth)
Components of a Computer System
CS101 - Introduction To Computer Concepts 7
• A CPU is on a chip called a microprocessor
• It continuously follows the fetch-decode-execute cycle:
fetch
Retrieve an instruction from main memory
decode
Determine what theinstruction is
execute
Carry out theinstruction
Central Processing Unit
CS101 - Introduction To Computer Concepts 8
• The CPU contains:
Arithmetic / Logic Unit
Registers
Control Unit
Small storage areas
Performs calculations and makes decisions
Coordinates processing steps
CPU Components
CS101 - Introduction To Computer Concepts 9
• System Software
– Interface between hardware and computer users
– Does not serve the needs of solving user’s problem
• Application Software
– Accessed directly by users to serve their needs
Computer Programs - Software Types
CS101 - Introduction To Computer Concepts 10
• System Software
– Operating System
• Windows, Linux, Unix, Mac OS
• User Interface (UI)
• File and database management
• Communication protocols (e.g., TCP/IP)
– System support software
• System Utilities
• Disk utilities (format, error-checking, defragmentation)
System Software
CS101 - Introduction To Computer Concepts 11
Application Software
• Application Software– General-purpose software
• Used for more than one application• Word processors, spreadsheets, DBMS, CAD systems• Solve a variety of problems
– Application-specific software • Used for only one application• Accounting systems• Space-shuttle control systems
CS101 - Introduction To Computer Concepts 12
Programming Languages
• A programming language specifies the words and symbols that we can use to write a program
• A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements
• The actual statements in a language , something like sentences, are referred to as “source code”
CS101 - Introduction To Computer Concepts 13
Language Levels
• There are four programming language levels:
– machine language
– assembly language
– high-level language (many specific to a academic discipline)
– fourth-generation language
• Each type of CPU has its own specific machine language
• The other levels were created to make it easier for people to work with programs.
CS101 - Introduction To Computer Concepts 14
Programming Language Example
Source Code Statement Lanaguage
Add one to my-total (COBOL)
ADD 1,@my-total (Basic Assemble Language)
mytotal = mytotal + 1 (Visual Basic, FORTRAN)
mytotal++ (C++)
set mytotal [expr mytotal +1] (PERL)
All of the above statements accomplish the same thing
CS101 - Introduction To Computer Concepts 15
Running Programming Languages
• A program must be translated into machine language before it can be executed on a particular type of CPU
• A compiler is a software tool which translates source code into a specific target language
• Often, that target language is the machine language for a particular CPU type
CS101 - Introduction To Computer Concepts 16
The Program Translation Process
Terms to Know:
Source Code
Object Code
Executable
Source
Object
Executable
TranslatorLinker
Loaderother programs
CS101 - Introduction To Computer Concepts 17
Programming Translation Example
Source Code Statement Level
Add one to my-total Application
ST 1, R5 AssemblyST my-total, R6ADD R5,R6ST R5,my-total
10011011 0001 0101 Machine Language for “ST 1,R5”
Instruction Code for ST (Store)
The number 1 in base 2
The number 5 in base 2 indicating CPU Register 5
CS101 - Introduction To Computer Concepts 18
Syntax and Semantics
• The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program
• The semantics of a program statement define what that statement means (its purpose or role in a program)
• A program that is syntactically correct is not necessarily logically (semantically) correct
• A program will always do what we tell it to do, not what we meant to tell it to do
CS101 - Introduction To Computer Concepts 19
Language Components
• Lexicon
– All legal words in the language
– Meaning and type
• Syntax– grammar rules
• Semantics
– meaning of command
CS101 - Introduction To Computer Concepts 20
Basic Program Development
errors
errors
Edit andsave program
Compile program
Execute program andevaluate results
CS101 - Introduction To Computer Concepts 21
Errors
A program can have three types of errors
1. The compiler will find syntax errors and other basic problems (compile-time errors)
1. If compile-time errors exist, an executable version of the program is not created
2. A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors)
3. A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors)
CS101 - Introduction To Computer Concepts 22
Debugging Techniques
• Step through programs
• Check variable values
• Use tools to stop program running when a value is reached
• Print out information from within your program
CS101 - Introduction To Computer Concepts 23
• EditorsEditors
• AssemblersAssemblers
• DebuggersDebuggers
• CompilersCompilers
• LinkersLinkers
• LoadersLoaders
• InterpretersInterpreters
Integrated Development Environments (IDEs) Integrated Development Environments (IDEs) combine several of the above programming toolscombine several of the above programming tools
Programming Tools and Support
CS101 - Introduction To Computer Concepts 24
Example of High-Level IDE (Visual Basic .NET)
Learn more about me in CS508 !!!
CS101 - Introduction To Computer Concepts 25
Program Text Editors
• Word processors format the appearance of the text
• Text editors
– Format the spacing between words for legibility
– Ideal for structured languages
– Text is the same font size
• Examples
– DOS – Edit
– Windows – Notepad, Wordpad
– Unix / Linux – ed, vi, emacs
• IDEs
– MS Visual C++, Symantec Visual Cafe
CS101 - Introduction To Computer Concepts 26
Interpreters
• Translates source code instructions into machine language and executes it one statement at a time
• Disadvantages
– Longer to execute, particularly bad for loops
– Uses more memory
• Advantage
– Faster testing and code modification
• Examples of interpreted languages
– Java, BASIC, LISP
CS101 - Introduction To Computer Concepts 27
Interpreter vs. Compiler
Resources during execution Interpreter Compiler
Contents in memory
Interpreter/compiler Yes No
Source code Partial No
Executable code Yes Yes
CPU cycles
Translation operations Yes No
Library linking Yes No
Application program Yes Yes
CS101 - Introduction To Computer Concepts 28
Where does memory fit in?
Computer Processing Components
• Major components of a computer
– CPU or Central Processing Unit
– Primary (internal) memory– Secondary (external memory)– Control Unit– Arithmetic Logic Unit– Input devices– Output devices
Control Unit
Arithmetic-Logic Unit
Main Memory
Input Devices
Output Devices
Network External Memory
CPU
CS101 - Introduction To Computer Concepts 29
CPU and Main Memory
CentralProcessing
Unit
MainMemory
Chip that executes program commands
Intel Pentium 4 orSun ultraSPARC III Processor
Primary storage area for
programs and data that are in
active use
Synonymous with RAM (Random
Access Memory)
CS101 - Introduction To Computer Concepts 30
Purposes of Memory
• Hold instructions so the CPU can fetch your program and execute it
• Keep your data available to the CPU to use when executing an instruction
• Work with the CPU to perform some really fast arithmetic
CS101 - Introduction To Computer Concepts 31
Memory Areas
• Main Memory
– Internal, primary, random access memory (RAM)
– Stores instructions and data
• Cache memory
– Smaller quantity of high speed memory, speed meaning quicker for the CPU to access
• Registers
– Specific high speed memory locations used repeatedly by instructions
– Helps in arithemetic
CS101 - Introduction To Computer Concepts 32
Memory Structure
Main memory is divided into many memory locations (or cells)
927892799280928192829283928492859286
Each memory cell has a numeric address, which uniquely identifies it
CS101 - Introduction To Computer Concepts 33
Analog vs. Digital
• There are two basic ways to store and manage data:
• Analog
– continuous, in direct proportion to the data represented
– music on a record album - a needle rides on ridges in the grooves that are directly proportional to the voltages sent to the speaker
• Digital
– the information is broken down into pieces, and each piece is represented separately
– music on a compact disc - the disc stores numbers representing specific voltage levels sampled at specific times
CS101 - Introduction To Computer Concepts 34
Digital Information is Stored in Memory
• Computers store all information digitally:
– numbers
– text
– graphics and images
– video
– audio
– program instructions
• In some way, all information is digitized - broken down into pieces and represented as numbers
CS101 - Introduction To Computer Concepts 35
Representing Text Data Digitally
• For example, every character is stored as a number, including spaces, digits, and punctuation
• Corresponding upper and lower case letters are separate characters
H i , H e a t h e r .
72 105 44 32 72 101 97 116 104 101 114 46
These numbers can be found in a decoding table
CS101 - Introduction To Computer Concepts 36
Binary Numbers
• Once information is digitized, it is represented and stored in memory using the binary number system
• A single binary digit (0 or 1) is called a bit
• Devices that store and move information are cheaper and more reliable if they have to represent only two states
• A single bit can represent two possible states, like a light bulb that is either on (1) or off (0)
• Permutations of bits are used to store values
CS101 - Introduction To Computer Concepts 37
Bit Permutations1 bit
01
2 bits
00011011
3 bits
000001010011100101110111
4 bits
00000001001000110100010101100111
10001001101010111100110111101111
Each additional bit doubles the number of possible permutations
CS101 - Introduction To Computer Concepts 38
Bit Permutations
• Each permutation can represent a particular item
• There are 2N permutations of N bits
• Therefore, N bits are needed to represent 2N unique items
21 = 2 items
22 = 4 items
23 = 8 items
24 = 16 items
25 = 32 items
1 bit ?
2 bits ?
3 bits ?
4 bits ?
5 bits ?
How manyitems can be
represented by
CS101 - Introduction To Computer Concepts 39
Storing Information
927892799280928192829283928492859286
Large values arestored in consecutivememory locations
1001101010011010Each memory cell stores a set number of bits (usually 8 bits, or one byte)
CS101 - Introduction To Computer Concepts 40
Look Back at our Example
927892799280928192829283928492859286
These two locations represent oneinstruction ST 1,R5 0001101000011010
1001101110011011
0001----0001----1011101110111011
These three locations represent oneinstruction LOAD R1,mytotal
00000101000001010000000000000000 location of mytotal
value = 5
Symbol Location
mytotal 9285
Memory Symbol Table
Memory Used for Instructions
Memory Used for Data
----------------
The ---- in 9281 and 0282 would be the string of 0,1 that equal 9285 in base 2
R1..R9 are special memory areas of the CPU much like your MEM button on a calculator
CS101 - Introduction To Computer Concepts 41
Programs and Memory Summary
• The computer will actually be looking at a set of zeroes and ones when executing instructions or working with data
• Programmers think of data in terms of numbers (to add / multiply) and characters (letters , or numbers that are not added -like zip codes)
• Programmers use variables as a way to set aside memory and keep data there during the program
• When setting up a variable, the programmer will say how much much memory is needed and whether the memory will hold numbers or letters
• Each variable you used in a program will be assigned a real memory address when the program runs or executes
CS101 - Introduction To Computer Concepts 42
Storage Capacity
• Every memory device has a storage capacity, indicating the number of bytes it can hold
• Capacities are expressed in various units:
KB 210 = 1024
MB 220 (over 1 million)
GB 230 (over 1 billion)
TB 240 (over 1 trillion)
Unit Symbol Number of Bytes
kilobyte
megabyte
gigabyte
terabyte