Download Six Different Phase for Executing C program

Document related concepts

Structured programming wikipedia , lookup

Compiler wikipedia , lookup

Library (computing) wikipedia , lookup

Supercomputer wikipedia , lookup

Computer cluster wikipedia , lookup

Parallel computing wikipedia , lookup

Transcript
CS 102: Section 1
Sussan Einakian
Objectives
 Basic Computer Concepts
 Computer Organization
 Computer Software/ Hardware
 Programming Languages
 The elements of C program environment
For some sample programs you can check the authors
website:
www.deitel.com/books/chtp7/
What is a Computer?
• Computer
– Device capable of performing computations and making
logical decisions million times faster than human.
– Computers process data.
– Today’s fastest supercomputers can perform thousands of
trillions (quadrillions) of instructions per second!
– Computer can perform more than 100,000 calculations per
second for every person on the planet!
3
Use of Computer
 Electronic health record
 Human Genome Project
 Amber Alert
 World Community Grid
 Medical Imaging
 One Laptop per Child
 Cloud Computing
 GPS
 Robots
 Email, Instant Messaging, Video Chat, FTP
 Internet TV
 Game Programming
Hardware-Software
 There are more than a billion general-purpose
computers, and billions more embedded computers are
used in cell phones, smart phones, tablet computers,
home appliances, automobiles and more
 Hardware
 A computer consist of various devices.
 Keyboard, screen, mouse, disks, memory, CD-ROM, and
etc.
 Software
 Programs that run on a computer.
 Computers process data based on sets of instructions called
computer programs.
Computers Before and Now
 Computers that might have filled large rooms and cost millions




of dollars decades ago are now inscribed on silicon chips
smaller than a fingernail, costing perhaps a few dollars each.
Silicon-chip technology has made computing so economical
that more than computers have become a commodity.
For many decades, hardware costs have fallen rapidly.
Every year or two, the capacities of computers have
approximately doubled without any increase in price.
This remarkable trend often is called Moore’s Law, named for
the person who identified it, Gordon Moore, co-founder of
Intel.
Information-processing cycle
 Consists of four basic operations:




Input
Processing
Output
Storage
Early Computers
For more information on early computers you can check this link:
http://www.computersciencelab.com/ComputerHistory/HistoryPt4.htm
IBM Card Punch or Batch Computing
The Von Neumann-Eckert Model
The famous mathematician John Von Neumann, that proposed the
stored program concept (in 1945).
often called Father of Modern Computing
Computer Organization
(Logical Units)
1) Input
2) Output
3) CPU
4) ALU
5) Memory
6) Secondary Storage
Computer Organization
 Regardless of differences in physical appearance, computers
can be envisioned as divided into various logical units or
sections:
1. Input unit (Receiving Section)

Obtains information from input devices (keyboard, mouse touch, voice)
2. Output unit (Shipping Section)

Outputs information (to screen, to printer, to control other devices)
3. Memory unit (Warehouse Section)

Rapid access, low capacity, stores input information (called as primary
memory)
4. Arithmetic and logic unit (ALU) (Manufacturing Section)

Performs arithmetic calculations and logic decisions
5. Central processing unit (CPU) (Administrative Section)

Supervises and coordinates the other sections of the computer
6. Secondary storage unit


15
Cheap, long-term, high-capacity storage, persitent
Stores inactive programs
Personal Computing, Distributed Computing, and
Client/Server Computing
 Personal computers (from 1977)
 Economical enough for individual
 Distributed computing
 Computing distributed over networks
 Client/server computing
 Sharing information across computer networks between
file servers and clients (personal computers)
16
New Generation of Computers
 A single finger, multi-touch computer screens can follow the
instructions of many fingers simultaneously.
 A wall-size screen developed by Perceptive Pixel can respond to as
many as 10 fingers or multiple hands.
New Computers
Combined with the newest wireless technology, prepare for computers
to be even more available than they are now.
New Generation of Sony
Computers by 2020
Computer Software
 The programs that allow the computer hardware to
operate.
 System Software:
 Operating Systems, language translators, and utilities
(Editors, Software used to create, copy , delete files).
 Application Software
 The type of program you will learn to write in this class.
Operating System
The OS as a Conductor
The OS coordinates the sharing and use of all the components in
the computer
25
Operating Systems
Operating Systems
 Manage smooth transitions between jobs
 Increased throughput

Amount of work computers process
 Batch processing (Early Computers)
 Do only one job or task at a time
 Submit the jobs to computer center
 Multitasking
 Computer resources are shared by many jobs or tasks
 Timesharing
 Computer runs a small portion of one user’s job then moves on to
service the next user
26
Operating System
 The software that contains the core components of the
operating system is called the kernel.
 Popular desktop operating systems include Linux,
Unix, Windows, and Mac OS X.
 Popular mobile operating systems used in
smartphones and tablets include Google’s Android,
Apple’s iOS (for iPhone, iPad and iPod Touch
devices), BlackBerry OS and Windows Phone 7 and
8.
Application Software
Programmers write instructions in various programming
languages, some directly understandable by computers and
others requiring intermediate translation steps.
Three types of programming languages
1.
Machine languages


Strings of numbers giving machine specific instructions
Example:
+1300042774
+1400593419
+1200274027
2.
Assembly languages


English-like abbreviations representing elementary computer
operations (translated via assemblers)
Example:
LOAD
ADD
STORE
28
BASEPAY
OVERTIMEPAY
SALARY
High-level Languages


Computer usage increased rapidly.
To speed up programming process.
3. High-level languages



Codes similar to everyday English
Use mathematical notations (translated via compilers)
Example:

Salary = basePay + overTimePay
Interpreter programs were developed to execute high-level language programs
directly, although more slowly than compiled programs.

Scripting languages such as JavaScript and PHP are processed by interpreters.

29
High Level Languages
• Fortran (Formula Translator)
– developed by IBM Corporation in the 1950s
– used for scientific and engineering applications that
require complex mathematical computations
• COBOL (Common Business Oriented Language)
– developed in 1959 by computer manufacturers, the
government and industrial computer users
– used for commercial applications that require precise
and efficient manipulation of large amounts of data
31
High Level Languages
 Pascal
 Developed by Professor Niklaus Wirth in 1971
 Designed for teaching structured programming
 Ada
 Developed
under the sponsorship of the U.S.
Department of Defense (DOD) during the 1970s and
early 1980s
 Able to perform multitasking
32
1.8 History of C
C
 Evolved by Ritchie from two previous programming languages, BCPL
and B in Bell Lab.
 Used to develop UNIX
 Used to write modern operating systems
 Hardware independent (portable)
 By late 1970's C had evolved to "Traditional C“
 Many of todays leading operating systems are written in C and/or C++.
 C is mostly hardware independent.
 With careful design, it’s possible to write C programs that are portable to
most computers.
 Standardization
 Many slight variations of C existed, and were incompatible
 Committee formed to create a "unambiguous, machine-independent"
33
definition
 Standard created in 1989, updated in 1999
C++
• C++
– Superset of C developed by Bjarne Stroustrup at Bell
Lab.
– It has its roots in C, providing a number of features that
improved C, and provides object-oriented capabilities
– Dominant language in industry and academia
• Learning C++
– Because C++ includes C, some feel it is best to master C,
then learn C++
– Starting in Chapter 18, we begin our introduction to C++
34
C++
 More important, it provides capabilities for objectoriented programming.
 Objects are essentially reusable software components
that model items in the real world.
 Using a modular, object-oriented design and
implementation approach can make software
development groups more productive.
 [Note: The programs in this book will run with
little or no modification on most current C
systems, including Microsoft Windows-based
systems, Linux system, and more.]
 Check out C Resource Center at
www.deitel.com/C to locate “getting
started” tutorials for popular C compilers and
development environments.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
 C systems generally consist of several parts:
 a program development environment,
 the language and
 the C Standard Library.
 C programs typically go through six phases to be
executed.
 These are: edit, preprocess, compile, link, load and
execute.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
Six Different Phase for Executing C
program
 Phase 1 consists of editing a file.
 This is accomplished with an editor program.
 Two editors widely used on Linux systems are vi
and emacs.
 Software packages for the C/C++ integrated program
development environments such as Eclipse and
Microsoft Visual Studio have editors that are
integrated into the programming environment.
 You type a C program with the editor, make
corrections if necessary, then store the program on a
secondary storage device such as a hard disk.
 C program file names should end with the .c
extension.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
Six Different Phase for Executing C
program
 In Phase 2, you give the command to compile the
program.
 The compiler translates the C program into machine
language-code (also referred to as object code).
 In a C system, a preprocessor program executes
automatically before the compiler’s translation phase
begins.
 It indicate that certain manipulations are to be performed
on the program before compilation.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
Six Different Phase for Executing C
program
 These manipulations usually consist of including
other files in the file to be compiled and performing
various text replacements.
 In Phase 3, the compiler translates the C program into
machine-language code.
 A syntax error occurs when the compiler cannot
recognize a statement because it violates the rules of
the language.
 Syntax errors are also called compile errors, or
compile-time errors.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
Six Different Phase for Executing C
program
• The next phase is called linking.
• C programs typically contain references to
functions defined elsewhere, such as in the
standard libraries or in the private libraries of
groups of programmers working on a particular
project.
• A linker links the object code with the code for the
missing functions to produce an executable image
(with no missing pieces).
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
Six Different Phase for Executing C
program
 The fifth phase is called loading.
 Before a program can be executed, the program must
first be placed in memory.
 This is done by the loader, which takes the executable
image from disk and transfers it to memory.
 Additional components from shared libraries that
support the program are also loaded.
 Finally, the computer, under the control of its CPU,
executes the program one instruction at a time.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
Problems That May Occur at Execution Time
 Programs do not always work on the first try.
 Each of the preceding phases can fail because of various errors
that we’ll discuss.
 For example, an executing program might attempt to divide by
zero (an illegal operation on computers just as in arithmetic).
 This would cause the computer to display an error message.
 You would then return to the edit phase, make the necessary
corrections and proceed through the remaining phases again to
determine that the corrections work properly.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
 You may have heard that C is a portable language and
that programs written in C can run on many different
computers.
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
 C is a rich language, and there are some part that are not
obvious in the language and some advanced subjects we
have not covered.
 For additional technical details on C, read the C Standard
document itself or the book by Kernighan and Ritchie
(The C Programming Language, Second Edition).
©1992-2010 by Pearson Education, Inc.
All Rights Reserved.
C Standard Library
 As you’ll learn in Chapter 5, C programs consist of pieces
called functions.
 You can program all the functions you need to form a C
program, but most C programmers take advantage of the
rich collection of existing functions called the C Standard
Library.
 Avoid reinventing the wheel.
 Instead, use existing pieces—this is called software reuse.
C Standard Library (Cont.)
 When programming in C you’ll typically use the
following building blocks:
 C Standard Library functions
 Functions you create yourself
 Functions other people (whom you trust) have created and
made available to you
C Standard Library (Cont.)
 The advantage of creating your own functions is that
you’ll know exactly how they work. You’ll be able to
examine the C code.
 The disadvantage is the time-consuming effort that goes
into designing, developing and debugging new functions.