Computer Programming CS 1 Introduction to Computers and Computer Technology Rick Graziani

advertisement
Computer Programming
CS 1 Introduction to Computers and Computer
Technology
Rick Graziani
Fall 2015
Computer Architecture
•
Central Processing Unit (CPU) or processor
– Arithmetic/Logic unit (ALU)
• Performs operations on data such as addition and subtraction
– Control unit
• Coordinating the CPU’s activities
• Holds input and results (output) for the ALU
– Registers
• Temporary storage for the CPU
– General registers
– Special purpose registers
Rick Graziani graziani@cabrillo.edu
2
A CPU can be:
A CPU can be:
1. A series of integrated circuits (chips) on one or more circuit boards
– Older mainframe and minicomputers
2. On a single integrated circuit known as a microprocessor
microprocessor = a CPU on a single chip
microcomputer = older term for a computer with a microprocessor(s)
(PC, Macintosh)
Rick Graziani graziani@cabrillo.edu
3
Computer Architecture
•
Bus
– Used to transfer bits between the CPU and RAM (main memory)
Rick Graziani graziani@cabrillo.edu
4
User interface
User Types
(Input)
2+ 3 =
Computer
Outputs
5
Rick Graziani graziani@cabrillo.edu
5
Computer Architecture
Value = 5
2+3=5
Value = 2
Value = 3
•
Task: Add two values stored in main memory (RAM)
– Data (two values) must be transferred from main memory to registers
within the CPU
– ALU: Values are added
– Result stored in main memory (RAM)
Rick Graziani graziani@cabrillo.edu
6
Computer Architecture
5
2+3 =5
2
2
3
3
2+3=5
•
Task: Add two values stored in main memory (RAM)
– Data (two values) must be transferred from main memory to registers
within the CPU
– ALU: Values are added
– Result stored in main memory (RAM)
Rick Graziani graziani@cabrillo.edu
7
Our CPU and the Pentium CPU
Rick Graziani graziani@cabrillo.edu
8
Stored Program Concept
Program
instruction
•
Stored program concept: A program can be encoded as bit patterns and
stored in main memory.
– CPU can then:
•
extract the instructions as needed (copy them into its registers)
•
execute them
Rick Graziani graziani@cabrillo.edu
9
Terminology
Op-code Operand
1
2
3
4
5
6
7
8
9
A
B
C
•
•
Description
RXY
RXY
RXY
0RS
RST
RST
RST
RST
RST
R0X
RXY
000
LOAD reg. R from cell XY.
LOAD reg. R with XY.
STORE reg. R at XY.
MOVE R to S.
ADD S and T into R. (2’s comp.)
ADD S and T into R. (floating pt.)
OR S and T into R.
AND S and T into R.
XOR S and T into R.
ROTATE reg. R X times.
JUMP to XY if R = reg. 0.
HALT.
Machine instruction: An instruction (or command)
encoded as a bit pattern recognizable by the CPU
Machine language: The set of all instructions recognized
by a machine (CPU)
Rick Graziani graziani@cabrillo.edu
10
Machine
Instruction Types
Op-code Operand
1
2
3
4
5
6
7
8
9
A
B
C
Description
RXY
RXY
RXY
0RS
RST
RST
RST
RST
RST
R0X
RXY
000
LOAD reg. R from cell XY.
LOAD reg. R with XY.
STORE reg. R at XY.
MOVE R to S.
ADD S and T into R. (2’s comp.)
ADD S and T into R. (floating pt.)
OR S and T into R.
AND S and T into R.
XOR S and T into R.
ROTATE reg. R X times.
JUMP to XY if R = reg. 0.
HALT.
• Machine Instruction Types
•
– Data Transfer: Copy data from one location to another
– Arithmetic/Logic: Use existing bit patterns to compute a new bit
patterns
– Control: Direct the execution of the program
More in a moment
Rick Graziani graziani@cabrillo.edu
12
Adding values stored in memory
2
3
2+3=5
5
Rick Graziani graziani@cabrillo.edu
13
Using machine language
Rick Graziani graziani@cabrillo.edu
14
Computer Architecture
2+3
Rick Graziani graziani@cabrillo.edu
=5
0
5
5
2
6
3
6E
5
6C
2
6D
3
15
Adding values stored in memory
Step 1
Step 2
2+3
=5
0
5
5
2
6
3
6E
5
6C
2
6D
3
Step 3
Step 4
Step 5
•
Data Transfer
– Instructions that request the movement (copying) of data from one location
to another
Rick Graziani graziani@cabrillo.edu
16
Adding values stored in memory
Step 1
Step 2
2+3
=5
0
5
5
2
6
3
6E
5
6C
2
6D
3
Step 3
Step 4
Step 5
•
ALU
– Instructions that tells the control unit to request an activity within the ALU
– Capable of performing operations other than basic arithmetic operations,
including: AND, OR, XOR.
Rick Graziani graziani@cabrillo.edu
17
Remember our half-adder? Adding two bits
0
1
Inputs: A, B
S = Sum
C = Carry
XOR
1
0
AND
A
0
+
B
1
=
=
C
S
2’s
1’s
0
1
• Adding two, eight bit values involves a
•
similar process, just more gates (2 + 3 = 5):
00000010 + 00000011 = 00001001
Rick Graziani graziani@cabrillo.edu
0
+ 1
---1
18
Adding values stored in memory
Step 1
Step 2
Step 3
Step 4
Step 5
•
Control
– Instructions that direct the execution of the program Jump or Branch
instructions: Directs the CPU to execute an instruction other than the next
one in the list.
• Unconditional Jump: Skip to Step 6
• Condition Jump: If the value is 0 then Skip to Step 6
Rick Graziani graziani@cabrillo.edu
19
The architecture of our machine
Address
00000000
00000001
00000010
00000011
11111111
•
•
Main Memory
– 256 cells: 00 through FF (Hex)
• 0000 0000 through 1111 1111
– Storage: 8 bits per cell
CPU
– 16 registers: 0 through F (Hex); 8 bits per cell
– Program counter: (Address of) Keeps track of the next instruction
– Instruction register: Contains the current instruction to be executed by
the ALU.
Rick Graziani graziani@cabrillo.edu
20
Converting Decimal, Hex, and Binary
Dec.
0
1
2
3
4
5
6
7
Hex.
0
1
2
3
4
5
6
7
Binary
0000
0001
0010
0011
0100
0101
0110
0111
Dec.
8
9
10
11
12
13
14
15
Hex.
8
9
A
B
C
D
E
F
Binary
1000
1001
1010
1011
1100
1101
1110
1111
1 Hex digit = 4 bits
Rick Graziani graziani@cabrillo.edu
21
Loading instructions into the computer
Rick Graziani graziani@cabrillo.edu
22
Parts of a Machine
Instruction
0011 0101 1010 0111
Op-code
1
2
3
4
5
6
7
8
9
A
B
C
Operand
Description
LOAD reg. R from cell XY.
LOAD reg. R with XY.
STORE reg. R at XY.
MOVE R to S.
ADD S and T into R. (2’s comp.)
ADD S and T into R. (floating pt.)
OR S and T into R.
AND S and T into R.
XOR S and T into R.
ROTATE reg. R X times.
JUMP to XY if R = reg. 0.
HALT.
Binary (16 bits)
1 Hex digit = 4 bits
Machine Language
• Each instruction involves two parts:
– Op-code: Specifies which operation to execute
• LOAD, ADD, STORE, etc.
– Operand: Gives more detailed information about the operation
• Interpretation of operand varies depending on op-code
Rick Graziani graziani@cabrillo.edu
23
Op-code
1
2
3
4
5
6
7
8
9
A
B
C
Parts of a Machine
Instruction
Operand
Description
LOAD reg. R from cell XY.
LOAD reg. R with XY.
STORE reg. R at XY.
MOVE R to S.
ADD S and T into R. (2’s comp.)
ADD S and T into R. (floating pt.)
OR S and T into R.
AND S and T into R.
XOR S and T into R.
ROTATE reg. R X times.
JUMP to XY if R = reg. 0.
HALT.
Store the bits found in register 5 in main memory cell A7
5
Rick Graziani graziani@cabrillo.edu
8
8
A
7
1010 0111
24
The machine cycle
Rick Graziani graziani@cabrillo.edu
25
Program Execution
Rick Graziani graziani@cabrillo.edu
26
The program is stored in main memory ready for
execution
1 Hex digit = 4 bits
Hard Disk Drive
00
FF
•
•
The program is copied put into main memory.
– Typically from permanent storage.
– Requires two memory cells per instruction:
• Instructions are 16 bits; memory cells are 8 bits
Program counter contains first instruction: A0
Rick Graziani graziani@cabrillo.edu
27
Performing the fetch step of the machine cycle
Rick Graziani graziani@cabrillo.edu
28
Registers
0
5
Program
Counter
A0
Instruction
Register
6
…
•
At the beginning of the first fetch:
– Program Counter = A0
Rick Graziani graziani@cabrillo.edu
6C
02
6D
03
6E
29
Registers
0
5
6
Program
Counter
A2
A0
Instruction
Register
156C
…
•
6C
02
6D
03
At the beginning of the first fetch:
6E
– Instruction at A0 (and A1) loaded into Instruction
register
– Program Counter = A2
Rick Graziani graziani@cabrillo.edu
30
Registers
0
5 02
6
Program
Counter
A2
Instruction
Register
156C
…
Load register 5 in main memory cell 6C
6C
02
6D
03
6E
• CPU analyzes the instruction
• Loads Register 5 with the contents of memory cell address
6C.
Rick Graziani graziani@cabrillo.edu
31
Registers
0
5 02
Program
Counter
A2
Instruction
Register
6
…
•
At the beginning of the next fetch:
– Program Counter = A2
Rick Graziani graziani@cabrillo.edu
6C
02
6D
03
6E
32
Registers
0
5 02
6 03
Program
Counter
A2
A4
Instruction
Register
166D
…
Load register 6 in main memory cell 6D
6C
02
6D
03
6E
•
•
•
•
Instruction at A2 (and A3) loaded into Instruction register
Program Counter incremented: A4
CPU analyzes the instruction
Loads Register 6 with the contents of memory cell address 6D.
Rick Graziani graziani@cabrillo.edu
33
Registers
0
2 02
Program
Counter
A4
Instruction
Register
3 03
…
•
At the beginning of the next fetch:
– Program Counter = A4
Rick Graziani graziani@cabrillo.edu
6C
02
6D
03
6E
34
Registers
0 05
5 02
6 03
Program
Counter
A6
A4
Instruction
Register
5056
…
Add: result into register 0, adding contents
of register 5 and register 6
Adds contents of register 5 and 6, placing result into register 0.
•
•
•
•
6C
02
6D
03
6E
Instruction at A4 (and A5) loaded into Instruction register
Program Counter incremented: A6
CPU analyzes the instruction
Adds contents of register 5 and register 6, storing the result into
register 0.
Rick Graziani graziani@cabrillo.edu
35
Registers
0 05
2 02
Program
Counter
A6
Instruction
Register
3 03
…
•
At the beginning of the next fetch:
– Program Counter = A6
Rick Graziani graziani@cabrillo.edu
6C
02
6D
03
6E
36
Registers
0 05
5 02
6 03
Program
Counter
A8
A6
Instruction
Register
306E
…
Store contents of register 0, in memory
cell address 6E
•
•
•
•
6C
02
6D
03
6E
05
Instruction at A6 (and A7) loaded into Instruction register
Program Counter incremented: A8
CPU analyzes the instruction
Stores contents of register 0 in the memory cell at address 6E.
Rick Graziani graziani@cabrillo.edu
37
Registers
0 05
5 02
Program
Counter
A8
Instruction
Register
6 03
…
•
At the beginning of the next fetch:
– Program Counter = A8
Rick Graziani graziani@cabrillo.edu
6C
02
6D
03
6E
05
38
Registers
0 05
5 02
6 03
Program
Counter
AA
A8
Instruction
Register
C000
…
Halt the program
•
•
•
•
6C
02
6D
03
6E
05
Instruction at A8 (and A9) loaded into Instruction register
Program Counter incremented: AA
CPU analyzes the instruction
Halts the program. (Program ends.)
Rick Graziani graziani@cabrillo.edu
39
Algorithm
• An algorithm is an ordered set of unambiguous, executable steps that
•
•
defines a terminating process.
Algorithms are part of many activities, even mundane ones.
Note: Researchers believe that the human mind including imagination,
creativity, and decision making, is actually the result of algorithm
execution.
– This is used in artificial intelligence
Rick Graziani graziani@cabrillo.edu
40
Example
• Obtain a basket of unshelled peas and an empty bowl.
• As long as there are unshelled peas in the basket continue
to execute the following steps:
a. Take a pea from the basket
b. Break open the pea pod
c. Dump the peas from the pod into the bowl
d. Discard the pod
Rick Graziani graziani@cabrillo.edu
41
Defining the Algorithm
Non-terminating sequence
1 2 3 4 5 6 7 8 9 10 11 … (this could go on for ever!)
Ambiguous
Organize the CDs
(By title? By artist? By genre?)
• An algorithm is an ordered set of unambiguous, executable steps that
•
•
defines a terminating process.
– Steps do not have to be executed in sequence.
Non-Terminating Sequence:
– Make a list of positive integers.
– The above requirement could not be performed in an algorithm,
because it does not terminate (it is infinite).
Unambiguous
– The instructions must be clear, specific and direct
– No room for creativity or interpretation
Rick Graziani graziani@cabrillo.edu
42
Abstract Nature of Algorithms
•
•
An algorithm can represented
in several ways.
Example: Algorithm to convert
temperatures from Celsius to
Fahrenheit:
– As an algebraic formula:
• F = (9/5)C + 32
– As a written instruction:
• Multiply the temperature
reading in Celsius by 9/5
and then add 32
Rick Graziani graziani@cabrillo.edu
43
Algorithm Representation
•
•
•
Algorithm requires some form
of a language.
Algorithm is a form of
communication
– Don’t want
misunderstandings
– Proper level of detail
– Proper level of difficulty
Problems arise when:
– Steps not precisely defined
– Not enough detail
Rick Graziani graziani@cabrillo.edu
44
Algorithm Representation
Op-code
1
2
3
4
5
6
7
8
9
A
B
C
Description
LOAD reg. R from cell XY.
LOAD reg. R with XY.
STORE reg. R at XY.
MOVE R to S.
ADD S and T into R. (2’s comp.)
ADD S and T into R. (floating pt.)
OR S and T into R.
AND S and T into R.
XOR S and T into R.
ROTATE reg. R X times.
JUMP to XY if R = reg. 0.
HALT.
LOAD reg. R from cell XY
• Primitive – A well defined set of building blocks (terms) used in
•
computer science.
– Arithmetic and logic operations built into the language
– Removes any ambiguity
– Includes its own syntax
Programming language – A collection of primitives (terms) and the
rules that state how the primitives can be combined to represent more
complex ideas.
Rick Graziani graziani@cabrillo.edu
45
Op-code
1
2
3
4
5
6
7
8
9
A
B
C
Operand
Description
LOAD reg. R from cell XY.
LOAD reg. R with XY.
STORE reg. R at XY.
MOVE R to S.
ADD S and T into R. (2’s comp.)
ADD S and T into R. (floating pt.)
OR S and T into R.
AND S and T into R.
XOR S and T into R.
ROTATE reg. R X times.
JUMP to XY if R = reg. 0.
HALT.
Store the bits found in register 5 in main memory cell A7
•
•
•
•
Machine language uses primitives
High-level programming languages (C++, Java) use
higher-level primitives, constructed from the lower-level
machine language primitives.
This results in an easier set of instructions to write.
More later.
Rick Graziani graziani@cabrillo.edu
46
Pseudocode
Pseudocode
1. Enter two numbers.
2. Add the numbers together.
3. Display the result.
• Pseudocode – A notational system in which ideas can be expressed
•
informally during the algorithm development process. (written
sentence)
Used independently of the programming language.
– Each programming language has its own primitives and rules.
Rick Graziani graziani@cabrillo.edu
47
Pseudocode
Conditional selection
• The selection of one of two possible activities depending upon the truth or
falseness of some condition
if condition then action
or
if condition then (activity)
else (activity)
•
If this condition is true, perform this activity.
If (sunny)
then (put on sunscreen)
•
If this condition is true, perform this activity, otherwise perform a different
activity.
If (sunny)
then (go swimming)
else (go bowling)
Rick Graziani graziani@cabrillo.edu
48
Repeating structure
• Another common semantic structure is the repeated execution of a
statement or sequence of statements as long as some condition
remains true.
while condition do activity
• Also known as a while loop
• Examples:
while (tickets remain to be sold)
do (sell a ticket)
Rick Graziani graziani@cabrillo.edu
49
Repeating structure
Counter
500
501
21
3
4
<End of loop>
Hello
Hello
Hello
Hello
…
Hello
Task: Write Hello 500 times.
Pseudocode
Counter = 1
While counter is less than or equal to 500, write the word “Hello” and add 1 to Counter.
Programming Code
Counter = 1
While (counter <= 500)
do
(print “Hello”;
Counter  Counter + 1)
Rick Graziani graziani@cabrillo.edu
50
For loop
Counter
500
501
21
3
4
<End of loop>
Hello
Hello
Hello
Hello
…
Hello
• A for loop can be used to accomplish the same thing as a while loop.
• Note: There are some differences between while and for loops.
Counter = 1
For (Counter <= 500)
do
(print the message “Hello”;
Counter  Counter + 1)
Rick Graziani graziani@cabrillo.edu
51
For loop
Counter
500
501
21
3
4
<End of loop>
Hello
Hello
Hello
Hello
…
Hello
• A for loop can be used to accomplish the same thing as a while loop.
• Note: There are some differences between while and for loops.
For (Counter = 1; Counter <= 500; Counter  Counter + 1)
do
(print the message “Hello”)
Rick Graziani graziani@cabrillo.edu
52
Programming Concepts
• Program consists of:
– Declarative statements
• Variables and data types
– Imperative statements
• Procedures, instructions, and algorithms
– Comments
• Enhance readability
• Used throughout the program
Rick Graziani graziani@cabrillo.edu
53
Variables and Data Types
Variable
Integer
125
Float
9.75
Character
d
• Variable – A location in RAM (main memory), given a descriptive
•
•
name, which stores information.
Data type – Variables are a type of day which can be:
– Number
• Integer: 0, 1, 2, 3, 4, 5, 6, etc.
• Real (floating point): 9.75, 300.5412
– Character: a, b, c, A, B, C, etc.
– String of text: “123 Main Street”
Working area or scratch pad for the program.
Rick Graziani graziani@cabrillo.edu
54
Data structure
1 2 3 4 5 …
… 24 25
B o o l o o t i a n
char Last_Name[25]
• Variables are often associated with a data structure.
• Data structure – A conceptual shape of arrangement of data
• Homogeneous Array
•
– Block of values of the same type
– Such as a one dimensional list or a two dimensional array (row,
column)
Example: String or array of characters
– char Last_Name[25]
Rick Graziani graziani@cabrillo.edu
55
Data structure
Frame
Dan
Sue
Gary
Mary
1
2
3
6
12
0
9
1
7
7
3
4
Integer pins [bowler, frame]
5
6
7
8
9
10
pins [Mary, 2] = 7
• Two dimensional array
– Row and column
– Integer pins [bowler, frame]
Rick Graziani graziani@cabrillo.edu
56
Assigning Value
Integer
125
Float
9.75
Character
•
d
Assignment statement – Statement which assigns a
value to a variable.
– Value assigned from user input
– Value assigned from another variable
– Value assigned from a specific value
– Value assigned from a calculation that can include both
variables and assigned values.
Fahrenheit = (9/5)Celcius + 32
Rick Graziani graziani@cabrillo.edu
57
1 #include <stdio.h>
This is a preprocessor command that includes standard input output header file (stdio.h)
from the C library before compiling a C program
2 int main()
This is the main function from where execution of any C program begins.
3 {
This indicates the beginning of the main function.
4 /*_some_comments_*/
whatever is given inside the command “/* */” in any C program, won’t be considered for
compilation and execution.
5 printf(“_____________”);
printf command prints the output onto the screen.
6 getch();
This command waits for any character input from keyboard.
7 return 0;
This command terminates C program (main function) and returns 0.
8 }
Graziani graziani@cabrillo.edu
This Rick
indicates
the end of the main function
58
•
•
#include <stdio.h>
Display “Hello world”
End the program
int main()
{
printf("Hello world");
return 0;
}
Note: Actual syntax has been simplified
#include <stdio.h>
int main()
{
int a;
•
•
•
•
•
Display “Enter an integer”
User enters a number
Display “Integer you have entered is”
Display the number the user entered
End program
printf("Enter an integer");
scanf(a);
printf("Integer that you have entered is”, a);
return 0;
}
Note: Actual syntax has been simplified
#include<stdio.h>
int main()
{
int a, b, c;
•
•
•
•
•
Display “Enter two numbers to add”
User enters two numbers
Add the two numbers
Display “Sum of the entered numbers =
“ and the sum
End program
printf("Enter two numbers to add ");
scanf(a,b);
c = a + b;
printf("Sum of entered numbers = ",c);
return 0;
}
Note: Actual syntax has been simplified
#include <stdio.h>
int main()
{
int n;
•
•
•
•
•
•
Display “Enter an integer”
User enters an integer
Determine if the integer is even
If the integer is even display “Even”
Else display “Oven”
End program
printf("Enter an integer");
scanf(n);
if (n/2 = 0)
printf("Even");
else
printf("Odd");
return 0;
Note: Actual syntax has been simplified
•
“I want you to write on the chalk board, ‘I will not throw
paper airplanes in class’, 500 times.”
Rick Graziani graziani@cabrillo.edu
67
Programming Concepts
Variable Count which
is type integer
Count
499
500
501
1
2
3
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
…
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
Rick Graziani graziani@cabrillo.edu
68
Variables
• Variables are declared, defined in the declaration section of the
program.
– Usually at the beginning of the program
– Examples:
int height_in_inches
char first_initial
float price
Rick Graziani graziani@cabrillo.edu
69
Variables
Count
499
500
501
1
2
3
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
…
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
• Variables:
– Can be given an initial value within the program
– Value may change from:
• Program instructions
• User input
Rick Graziani graziani@cabrillo.edu
70
Programming Concepts
Variable Count which
is type integer
Count
• Count = 1
• For Loop – As long as Count is less than or equal to 500
•
– Add 1 to Count
– Print “I will not throw paper airplanes in class”
Exit program
501
500
499
3
2
1
Software Development
Definitions
Software or Program
Instructions that tell the
computer what to do
Programmer
Someone who writes
computer programs
Rick Graziani graziani@cabrillo.edu
73
CPU Instruction Set
Instruction Set
0001
0010
0011
0100
0101
0110
0111
1000
1001
Instruction
Move
Compare
Bit test
Bit clear
Bit set
Add
See group 10
See groups 11, 13, 14
Move byte
Instruction Set
A vocabulary (list) of instructions which can be executed
by the CPU
• The only instructions the CPU can run or execute
• Example of a CPU’s Instruction Set
Rick Graziani graziani@cabrillo.edu
74
First Generation Languages
(Machine Language)
• Programming computers using the CPU’s instruction set
• Also known as Machine Language
• (timeline)
Machine Code File
A software file which contains the instructions from the CPU’s
instruction set.
Rick Graziani graziani@cabrillo.edu
75
First Generation Languages
(Machine Language)
Advantages of First Gen.
• Software programs execute (run) relatively very
quickly
• Software programs are relatively small in size
• (Insignificant advantages today)
Disadvantages of First Gen.
• Difficult to write, very detailed and takes a long time
• Difficult to read
• Difficult to debug
debug = the process to find mistakes in a software
program
Rick Graziani graziani@cabrillo.edu
76
Second Generation Languages
(Assembly Language)
Op-code
1
2
3
4
5
6
7
8
9
A
B
C
Description
LOAD reg. R from cell XY.
LOAD reg. R with XY.
STORE reg. R at XY.
MOVE R to S.
ADD S and T into R. (2’s comp.)
ADD S and T into R. (floating pt.)
OR S and T into R.
AND S and T into R.
XOR S and T into R.
ROTATE reg. R X times.
JUMP to XY if R = reg. 0.
HALT.
Assembly Language = The English-like instructions which are
equivalent to the CPU’s instruction set
Source Code= The actual instructions written by a programmer
Compiler = Software which translates source code instructions of a
particular language into machine code
Rick Graziani graziani@cabrillo.edu
77
Second Generation Languages
(Assembly Language)
Question: Which of these two files (source code file or
machine code file) will the user need to run this
software program?
Advantages of Second Gen.
• Easier to read than first gen.
• Easier to write than first gen.
• Easier to debug than first gen.
Disadvantages of Second Gen.
• Still very difficult to write programs
Rick Graziani graziani@cabrillo.edu
78
Using a compiler
Rick Graziani graziani@cabrillo.edu
79
Using an Interpreter
Rick Graziani graziani@cabrillo.edu
80
Interpreter versus Compiler
Rick Graziani graziani@cabrillo.edu
81
Third Generation Languages
(High level languages)
Languages which are somewhere between
machine language and the human
language.
FORTRAN (Formula Translation) - 1950's
Language to allow scientists and engineers to program
computers.
COBOL (Common Business Oriented Language) - 1960
Language primarily designed for US government and
defense contractors to program business
applications on the computer. Grace Hopper was
one of the developers of COBOL.
BASIC (Beginner's All-purpose Symbolic Code) - 1960's
Alternative language to FORTRAN for beginning
programming students.
Rick Graziani graziani@cabrillo.edu
82
Third Generation Languages
(High level languages)
Pascal (named after Blaise Pascal, 17th century French mathematician) 1970's
Language to teach proper structured programming.
Structured programming = Programming technique used to make
programming more productive and easier to write. Stresses simplistic,
modular programs.
ADA (named after Ada Lovelace (programmed the 19th century 'analytical
engine') - late 1970's
Language developed to replace COBOL.
Rick Graziani graziani@cabrillo.edu
83
Third Generation Languages
(High level languages)
C (successor to BCPL or "B") - 1970's
Popular programming language on computers from
microcomputers to super computers.
Faster and more efficient language. Very powerful language.
Source code example of a C Program (Displays Hello World!
on the screen.)
#include <stdio.h>
main()
{
printf("Hello World!");
}
C++ (pronounced "C plus plus") - 1980's
Object oriented language which is compatible with C.
JAVA
Rick Graziani graziani@cabrillo.edu
84
Third Generation Languages
(High level languages)
Advantages
• Easier to read, write and debug
• Faster creation of programs
Disadvantages
• Still not a tool for the average user to create
software programs
• Requires very good knowledge of programming and
of the language
Rick Graziani graziani@cabrillo.edu
85
Download