1.0 Intro - COMP208
1.0 Intro - COMP208
programming languages
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
What is a computer? 3
Computer: an electronic device capable of performing
commands. The basic commands that a computer performs
are input (get data), output (display result), storage and
performance of arithmetic and logical operations.
n Be able to acquire or read data of all types
n Have the facility to store and organize data
n Be able to process data
n Have devices to output the processed data
n Be easily connectable to other computers using communication
networks for widely disseminating information
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
What is a computer? 3
Computer: an electronic device capable of performing
commands. The basic commands that a computer performs
are input (get data), output (display result), storage and
performance of arithmetic and logical operations.
n Be able to acquire or read data of all types
n Have the facility to store and organize data
n Be able to process data
n Have devices to output the processed data
n Be easily connectable to other computers using communication
networks for widely disseminating information
Input ACQUIR PROCES OUTPU Disseminate
STORE
data results
Numbers Data Data Data Result Numbers
Text acquisition storage processor display Text
Images units units (CPU) unit Images
Audio Audio
Video Video
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
4
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (1) 5
n Hardware
• the machines, wiring, and other physical
components of your computer such as the
monitor, mouse, keyboard, ...
n Software
• the programs and other operating information
used by a computer
n Mouse:
• a small hand-held device that is dragged across
a flat surface to move the cursor on a computer
screen, typically having buttons that are pressed
to control computer functions
n Trackball:
• a small ball set in a holder that can be rotated
by hand to move a cursor on a computer screen
n Speakers:
• used to produce music and other sounds
n Printers:
• a machine linked to a computer for printing text
or pictures onto paper
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (4) 8
Hardware: 3. Memory:
n Random Access Memory (RAM) / main memory
hold the currently program being executed and the data currently
being processed
• read/write memory
• volatile memory
n Cache memory:
• a high speed memory that is used as a staging area for the processor
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (5) 9
Measuring Memory:
Unit Abbreviation Size (bytes)
bit b 1/8
byte B 1
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (6) 10
Hardware: 4. CPU:
n Central Processing Unit (CPU) / microprocessor
• the part of a computer in which operations (instructions) are controlled and
executed (data processing)
Today’s fastest
supercomputers can perform
hundreds of billions of
additions per second!
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
e200z1 Overview
11
OnCE/NEXUS
CPU
subsystems:
MEMORY
- Instruction unit: controls the MANAGEMENT LR INTEGER
CR
flow of instructions UNIT SPR CTR GPR EXECUTION
UNIT
XER
ADDRESS
MULTIPLY
-
32
- Integer unit, floating point unit:
DATA
EXTERNAL
used to process arithmetic and SPR
INTERFACE DATA
logical instructions. Adds,
32
(MTSPR/MFSPR)
subtracts, compares, shifts and
CONTROL
PC BRANCH
rotates UNIT UNIT
N LOAD/
STORE
- Load/store unit: executes UNIT
instructions that move data
between the GPRs and the
memory subsystem
DATA BUS INTERFACE UNIT
- ...
32 32 N
ADDRESS DATA CONTROL
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Figure 1-1. e200z1 Block Diagram
so contains an instruction prefetch buffer to allow buffering of instruction
structions Elements ofbuffer
proceed from this a computer system
to the instruction decode(8) 12
stage by ente
de register IR.
Table 4-1. Pipeline Stages
n How CPU executes program?
Stage Description
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (9) 13
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (10) 14
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (11) 15
Hardware: 5. Secondary memory:
n Optical disc memories
use a laser beam to enter data as spots on the disk surface. To read
data, the laser scans the disk and a lens picks up different light
reflections from the various spots
➡ CD-ROM:
• much slower than hard disk
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (12) 16
Speed
Cost
Size
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (13) 17
n Six logical units in every computer:
1. Input unit
• Obtains information from input devices (keyboard,
mouse)
2. Output unit
• Outputs information (to screen, to printer, to control other
devices)
3. Memory unit
• Rapid access, low capacity, stores input information
4. Arithmetic and logic unit (ALU)
• Performs arithmetic calculations and logic decisions
5. Central processing unit (CPU)
• Supervises and coordinates the other sections of the
computer
6. Secondary storage unit
• Cheap, long-term, high-capacity storage
• Stores inactive programs
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (14) 18
Software
Operating system
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (15) 19
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Elements of a computer system (16)
Evolution of Operating system: 20
n a Batch processing
– Do only one job or task at a time
– Users generally submitted their jobs to a computer center on decks of
punched cards
n Operating systems
– Manage transitions between jobs
– Increased throughput
• Amount of work computers process
n Multiprogramming
– Computer resources are shared by many jobs or tasks
– Users still submitted jobs on decks of punched cards
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
22
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Computing Environments (1) 23
n In the early days of computers, there was only one environment, the mainframe
computer hidden in a central computing department. With the advent of
minicomputers and personal computers, the environment changed with computers on
virtually every desktop. In this section we describe several different environments.
n Distributed computing
– Computing distributed over
networks
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Computing Environments (2) 24
n Client/server computing
– Sharing of information across computer networks between file servers
and clients (personal computers)
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
25
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (1) 26
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (1) 26
➡ efficient to store
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (1) 26
OFF - 0 ON - 1
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (1) 26
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (1) 26
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
First 6 110 6 6
Seventeen 7 111 7 7
Positive 8 1000 10 8
Integers 9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (3) 28
Encoding of decimal numbers:
1110
Base
1 0 1 12
Most Significant Least Significant
Bit (MSB) Bit (LSB)
000 0
001 1
0 0 0
010 2
0 1 1 2 bits 4 different values 3 bits 8 different values
011 3
1 0 2 0⇾3 0⇾7
100 4
1 1 3
101 5
110 6
111 7
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (3) 28
Encoding of decimal numbers:
1110
Base
1 0 1 12
Most Significant Least Significant
Bit (MSB) Bit (LSB)
000 0
001 1
0 0 0
010 2
0 1 1 2 bits 4 different values 3 bits 8 different values
011 3
1 0 2 0⇾3 0⇾7
100 4
1 1 3
101 5
110 6
111 7
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (4) 29
2 ÷ 2 = 1 Remainder 0
1 ÷ 2 = 0 Remainder 1 0 1
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (5) 30
Since base 16 is being used, 16 digits are needed. There are only 10
decimal digits, so the capital letters A to F are used to represent the
numbers 10 to 15. A = 10, B = 11, up to F = 15.
Example: 1111 11112 = F F16 = 25510
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (6) 31
Representation of characters:
n Numeric data: Using binary number system
n Non numeric data: Using standard encoding system:
➡ ASCII (American Standard Code for Information Interchange):
★ the most widely used code (personal computers)
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (7) 32
ASCII:
Examples: 100 0001 is 41 (hex) or 65 (decimal). It represents 'A'
100 0010 is 42 (hex) or 66 (decimal). It represents 'B'
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (7) 32
ASCII:
Examples: 100 0001 is 41 (hex) or 65 (decimal). It represents 'A'
100 0010 is 42 (hex) or 66 (decimal). It represents 'B'
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (7) 32
ASCII:
Examples: 100 0001 is 41 (hex) or 65 (decimal). It represents 'A'
100 0010 is 42 (hex) or 66 (decimal). It represents 'B'
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (8) 33
Exercises:
1. Convert the following decimal numbers to binary form:
1. 39
2. 512
1. 1101
2. 11011
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The language of a computer (9) 34
Exercises:
3. Convert the following numbers to decimal:
1. 448
2. A9F16
3. 7548
1. 618
2. 3A916
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
35
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The evolution of programming 36
languages (1)
n Computers process data under the control of sets of instructions called
computer programs need of programming languages
n Three types of programming languages:
1. Machine languages (1940’s)
• Strings of bits giving machine specific instructions
• Example: 100100 010001 Let’s consider the
100110 010010
equation:
100010 010011
wages = rate . hours
2. Assembly languages (1950’s)
• English-like abbreviations (called mnemonic) representing
elementary computer operations (translated via assemblers)
• Example:
LOAD rate Assembler: A program that translates a
ADD hours program written in assembly language into
STORE wages an equivalent program in machine language
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The evolution of programming 37
languages (2)
3. High-level languages (1960’s)
• Codes similar to everyday English (translated via compilers)
• C, C++ and Java are all high-level languages
• Example:
in C, you write the weekly wages equation as follows:
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The evolution of programming 37
languages (2)
3. High-level languages (1960’s)
• Codes similar to everyday English (translated via compilers)
• C, C++ and Java are all high-level languages
• Example:
in C, you write the weekly wages equation as follows:
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
components that model items in the real world. Using a modular, object-oriented design
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The evolution of programming 39
14
languages (4)
Chapter 1 Introduction to Computers, the Internet and the Web
Other high-level languages:
Programming
language Description
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Programming methodologies 41
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Programming methodologies 41
! Objects
– Reusable software components that model items in the real world
– Meaningful software units
- Date objects, time objects, audio objects,etc.
- Any noun can be represented as an object
– More understandable, better organized, and easier to maintain than
procedural programming
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
42
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
History of C 43
n The C programming language was designed by Dennis Ritchie at
Bell Laboratories in the early 1970s
n Evolved from two previous programming languages, BCPL and B
n Traditionally used to write operating systems and compilers / Used to
develop UNIX
n By late 1970's C had evolved to "Traditional C"
n Hardware independent (portable)
n Standardization:
➡ Many slight variations of C existed, and were incompatible
➡ Committee formed to create a "unambiguous, machine-independent" definition of the
language
➡ Standard created in 1989 by ANSI (American National Standards Institute) known as
ANSI C, updated by ISO (International Organization for Standardization ) in 1999 and
is known as C99
➡ In 2007, work began on another revision of the C standard, informally called "C1X"
until its official publication on 2011-12-08 C11
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
History of C - Built for Performance 44
1.6 The C Programming Language 11
n C is widely used to develop systems that demand performance:
Application Description
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
The C standard library 46
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
47
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (1) 48
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (2) 49
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n Comments:
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (3) 50
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n #include <stdio.h>
– Preprocessor directive
• Tells computer to load contents of a certain file
– <stdio.h> allows standard input/output operations
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (4) 51
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n int main()
– C programs contain one or more functions, exactly one of which must be main
– Parenthesis used to indicate a function
– int means that main "returns" an integer value
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (4) 51
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n int main()
– C programs contain one or more functions, exactly one of which must be main
– Parenthesis used to indicate a function
– int means that main "returns" an integer value
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (4) 51
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n int main()
– C programs contain one or more functions, exactly one of which must be main
– Parenthesis used to indicate a function
– int means that main "returns" an integer value
– Braces ({ and }) indicate a block
• The bodies of all functions must be contained in braces
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (4) 51
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n int main()
– C programs contain one or more functions, exactly one of which must be main
– Parenthesis used to indicate a function
– int means that main "returns" an integer value
– Braces ({ and }) indicate a block
• The bodies of all functions must be contained in braces
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (5) 52
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n printf( "Welcome to C!\n" );
– Instructs computer to perform an action
• Specifically, prints the string of characters within quotes (" ")
– Entire line called a statement
• All statements must end with a semicolon (;)
– Escape character (\)
• Indicates that printf should do something out of the ordinary
• \n is the newline character
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (5) 52
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7
8
{
printf( "Welcome to C!\n" );
Do not
9 forget
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n printf( "Welcome to C!\n" );
– Instructs computer to perform an action
• Specifically, prints the string of characters within quotes (" ")
– Entire line called a statement
• All statements must end with a semicolon (;)
– Escape character (\)
• Indicates that printf should do something out of the ordinary
• \n is the newline character
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (6) 53
1 /* A first program in C */
2
3 #include <stdio.h>
4
5 /* function main begins program execution */
6 int main()
7 {
8 printf( "Welcome to C!\n" );
9
10 return 0; /* indicate that program ended successfully */
11
12 } /* end function main */
Welcome to C!
n return 0;
– A way to exit a function
– return 0, in this case, means that the program terminated normally
n Right brace }
– Indicates end of main has been reached
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
A simple C program (7) 54
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
55
Outline
1. What is a computer?
2. Elements of a computer system
3. Computing environments
4. The language of a computer
5. The evolution of programming languages
6. Programming methodologies
7. History of C
8. The C standard library
9. A simple C program
10. Basics of a Typical C Program Development Environment
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
Basics of a Typical C Program
56
Phase 1:
Phase 2:
1. Edit
Preprocessor Preprocessor program
Syntax error Disk
processes the code.
Phase 3:
3. Compile
Linker links the object
Linker code with the libraries,
Disk
creates an executable file and
stores it on disk.
Primary
4. Link Loader
Memory
5. Load Phase 5:
Loader puts program
in memory.
6. Execute
...
Disk
Primary
Memory
CPU
Phase 6:
CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
executes.
...
Version Description
Alpha An alpha version is the earliest release of a software product that’s still under
active development. Alpha versions are often buggy, incomplete and unstable
and are released to a relatively small number of developers for testing new fea-
tures, getting early feedback, etc.
Beta Beta versions are released to a larger number of developers later in the devel-
opment process after most major bugs have been fixed and new features are
nearly complete. Beta software is more stable, but still subject to change.
Release Release candidates are generally feature complete and (supposedly) bug free and
candidates ready for use by the community, which provides a diverse testing environ-
ment—the software is used on different systems, with varying constraints and
for a variety of purposes. Any bugs that appear are corrected, and eventually
the final product is released to the general public. Software companies often
distribute incremental updates over the Internet.
Continuous Software that’s developed using this approach generally does not have version
beta numbers (for example, Google search or Gmail). The software, which is
hosted in the cloud (not installed on your computer), is constantly evolving
so that users always have the latest version.
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
58
Computer Communications
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
History of the Internet
59
n Packet switching
n The transfer of digital data via small packets
n No centralized control
n If one part of the Internet fails, other parts can still operate
n TCP/IP
n Bandwidth
n Information carrying capacity of communications lines
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages
History of the World Wide Web
60
17 Juin
Dr Rola 2010
Kassem An overview of computers and programming languages