Sunteți pe pagina 1din 42

PROGRAMMING

FUNDAMENTALS
Dr. Sheikh Faisal Rashid
shfaisal@gmail.com,uet.edu.pk
Department of Computer Science and
Engineering UET Lahore
INTRODUCTION
Machine language
Programming Languages
Our First Program
MACHINE INSTRUCTION
What’s a program
What Do Instructions Look Like
Machine Instruction
Parts of a Machine Instruction
Instruction Lengths
Machine Instruction Types
Example: An Instruction
Example: Program in Machine Codes
PROGRAMING
LANGUAGES
Programming Language
Design Considerations
Assembly Language
Assembly Language Characteristics
Assembly Language Example
Third Generation Languages
Language Translators
Formal Languages
Timeline of Programming Languages
Programming Paradigms (1/2)
Programming Paradigms (2/2)
Imperative Programming Language
Example of Data Declaration
Elements of an Imperative PL
Translating a Program
Syntax Diagram
Algebraic Expression Syntax
Example of Parsing An Expression
Code Generation and Optimization
Expressions Representation
• All of programming falls under the domain of mathematics
• We cannot use mathematical notation in programming
languages, and thus we must use other means of
describing our intentions
Expression Representation in C++

2(x +3 y) 2*(x + y)
n
3 (n*n*n)/3
1
9.8s 2  v0 s
2
0.5*9.8*s*s + v0*s

sin(x) sin(x)
|x| abs(x)
x
sqrt(x)
HELLO WORLD!
Our first program
#include <iostream>

int main();

int main() {
std::cout << "Hello world!";
std::cout << std::endl;

return 0;
}
Our first program
• There are two approaches we can take to compiling and
executing this code:
• Using an Integrated Development Environment (IDE)
• We will use Eclipse in the laboratories
• Using an on-line compiler such as http://cpp.sh/

• On-line compilers, however:


• May not always be available
Saint Helena
• Are useless for larger projects
Our first program
Our first program
• When you select the Run button, text is printed to the
console output

• Question: What is happening behind the scene?


Steps in generating an executable
program
• The program undergoes the Program
following four steps in order to Code
create an executable program
that you can run
• Step 1: Creating the program using a
programming language, and writing it
using an editor
Steps in generating an executable
program
• The program undergoes the Program
following four steps in order to Code
create an executable program
that you can run
• Step 1: Creating the program using a Compiler
programming language, and writing it
using an editor
• Step 2: Compiling the program into
machine-language code. This step
includes preprocessing the program
as well
Steps in generating an executable
program
• The program undergoes the Program
following four steps in order to Code
create an executable program
that you can run
• Step 1: Creating the program using a
programming language, and writing it Compiler
using an editor
• Step 2: Compiling the program into
machine-language code. This step
includes preprocessing the program Linker
as well
• Step 3: Linking together the program
with other helper programs into a
single executable program
Steps in generating an executable
program
• The program undergoes the Program
following four steps in order to Code
create an executable program that
you can run
• Step 1: Creating the program using a
programming language, and writing it Compiler
using an editor
• Step 2: Compiling the program into
machine-language code. This step
includes preprocessing the program as
well Linker
• Step 3: Linking together the program
with other helper programs into a
single executable program
• Step 4: Executing the program. Executable
program
Summary
• In this presentation, you now
• Have an overview of how computers executing instructions
• These are encoded in binary: 0s and 1s
• Understand that programming languages allow us to define
programs using a human-readable interface
• The program must be compiled into an executable and run
• Have written your first program: the ubiquitous Hello world!
• Saw this output on http://cpp.sh
• The first lab includes installing the Eclipse IDE
• You are not required to use Eclipse, but it is the only IDE that is
supported
• Understand the steps of compilation

S-ar putea să vă placă și