You are on page 1of 26

DFC10042

PROBLEM SOLVING &


PROGRAM DESIGN
TOPIC 1

INTRODUCTION TO PROGRAMMING
LANGUAGE

(part 2)
Once this
question
arise …
Programming ??
Is performed to solve a Programming
specific problems
Programming
A planning process for a
Concepts sequence of instruction to
be executed by the
computer
Terminologies

Program Programming Programmer

A set of Programming is a Programmer is a


step-by-step process of person who writes
instructions that designing/ creating the program.
directs a computer a program.
to perform a
specific task and to
produce the
required results.
TRANSLATOR
Scenario Overview
To help you understand,
let us discuss situation
below : Person A :
• Stakeholder from Japan
• Doesn’t know Malay/ English
Language
C
Person B :
• Project manager from Malaysia
A B
• Doesn’t know Japanese
Language

Person C :
• The TRANSLATOR
• Knows how to speak both
Malay & Japanese Language
Scenario Overview
To help you understand,
let us discuss situation
below :

C
1. Will they
manage to
A B
communicate?
2. How?
• Translates a computer program
(source code) into machine
Translator language (object code) that the
computer can understand.
is.. • Checks syntax of a program to
ensure the programming
language is used correctly, by
giving you the syntax-error

A program messages, which is known as


diagnostics.
• Produces descriptive error
that messages known as syntax-
error to programmer if there
are errors in the programs.
• The key to understanding these
early stored-program computers
as well as the computers we still
use today is …

Why do we
< to realize that every
need one? This language is called
CPU understands only
machine language.
one language! >
TRANSLATOR

TWO main reason on why


would we need one…
1. numeric language
• Memory inside your computer can only
store numeric data
TWO • Computer only talks in binary number
• when you work with text (typing, view web
main page, etc.), the computer is working with
binary numbers.

reason on • writing machine language programs is very


slow, tedious, and error-prone

why
would we 2. different CPU family = different machine
language
• because of this; machine language programs
need are inherently non-portable

one… • you can't run your copy of Word for Windows,


for example, on your iPad or iMac.
Assembler
Translates assembly language
into machine code

Compiler
A software system that
translates programs (HLL)

Translator into the machine language


(called binary code -LLL).

Types
Interpreter
Executes other programs
directly, running through
program code and executing
it line-by-line.
Let’s recall back See how the translator play it’s role in
to this example translating human like language (HLL)
into machine language?
ASSEMBLER

• Translates the whole program at one time.


• Example of pieces of code :
LDA #4 converts to 0001001000100100
11101 100000 100000

11110
sseg segment stack db 256 dup(?)

sseg ends
10111000

dseg segment 11101000

data db “2 x 4 = ” 11111100

dseg ends
Assembler 10111000

cseg segment 10001110 11011000

assume cs:cseg:ds:sdeg:ss:sseg.es:nothing 10111000

Start proc far 10001110 11000000

Assembly Language Machine Language


COMPILER

The Concepts :

Instead of translating virtual machine code into native


machine code every time you run the program, just do the
translation once.

Save the translated code on disk or tape and reuse it every


time you need to run your program.

Grace Hopper
COMPILER

# include <stdio.h>

main( ) 11101 100000 100000

{ 11110

int x, y, z, sum; 10111000


double avg; 11101000
printf(" Enter 3 numbers:"); 11111100
scanf("%d %d %d",&x, &y, &z); Compiler 10111000
sum = x + y + z;
10001110 11011000
avg = sum / 3;
10111000
printf("x = %d y = %d z = %d ", x, y, z);
10001110 11000000
printf("the average is = %f",avg);

return 0;

}
C Language Machine Langeage
INTERPRETER

• Executes other programs directly, running through program code and


executing it line-by-line.
• As it analyses every line it will be slower than running compiled code but
it can take less time to interpret program code
• Rather than to compile and then run it
• This is very useful when prototyping and testing code.
• Are written for multiple platforms, this means code written once can be
run immediately on different systems without having to recompile for
each.
• Examples of this include flash based web programs that will run on your
PC, MAC, games console and Mobile phone.
Relationship Between COMPILER
vs. INTEPRETER
The interpreter is kind of like the interpreters
One way to
at the Google translate. The understand the
words are translated as they occur. difference between
an interpreter and
a compiler is to
A compiler is more like the translator of a think about the
book. The translator produces a new different ways we
manuscript that is independent of the original. convert between
human languages.
Programming Language
Real Life Application
Example:
Cash withdrawal from ATM machine.
STEP ACITVITY
First step Data entered by user are stored in
memory as an input
Second CPU will instruct the program to Cash
step process the card number and ATM pin withdrawal
with the data in memory concurrently.
Program will execute the transaction from ATM
chosen by the user and store the machine.
result in memory.
Third step The outputs are money withdrawal
and receipt
Class Activity 2

• Topic :
Programming Languages
Real Life Applications
• Base on your understanding :
• List ONE example of Real-
Life Applications of
Programming Language
• Briefly explain the
example.
End of
Lecture 1 – Part 2

See you next class

Topic :
Problem Solving Methods

You might also like