0% found this document useful (0 votes)
57 views31 pages

Cos 101 Module 5 Presentation

The document provides an overview of programming languages, categorizing them into machine language, assembly language, and high-level languages, each with its own characteristics, advantages, and disadvantages. It also discusses programming paradigms, algorithms, and methods for representing algorithms such as flowcharts and pseudo-code. Additionally, it explains the roles of compilers and interpreters in translating high-level languages into machine code.

Uploaded by

www.vic2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views31 pages

Cos 101 Module 5 Presentation

The document provides an overview of programming languages, categorizing them into machine language, assembly language, and high-level languages, each with its own characteristics, advantages, and disadvantages. It also discusses programming paradigms, algorithms, and methods for representing algorithms such as flowcharts and pseudo-code. Additionally, it explains the roles of compilers and interpreters in translating high-level languages into machine code.

Uploaded by

www.vic2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

PROGRAMMING THE

COMPUTER

1. PROGRAMMING LANGUAGES
2. ALGORITHMS
3. FLOWCHARTS
PROGRAMMING LANGUAGES

 A programming language is a way of communication between a computer


programmer and a computer itself. A programmer is the person that writes a set
of instructions using a programming language to instruct the computer to
perform a task. A program is a set of instructions that are logically related.
 programming languages use syntax inform of vocabulary. This syntax is a set of
rules use by programmers to write programs that computer understands.
Format of a programming language instruction

Operation Code Operand


(Opcode) (Address)

The two parts of a programming language instruction are:

1. Operation Code (Opcode): This is the part that


instructs a computer about the operation to be
performed.

2. Operand: This is the part that instructs the computer


about the location of the data on which the operation
stated by the opcode is to be performed.

For example, look at this instruction Add A and B, “Add” is


the Opcode while A & B are the operands.
 Operation that can be performed by the opcode instruction sets
include:
1. Logical operations
2. Arithmetic operations
3. Branch operations
4. Data movement operations
Categories of programming
language
 Machine language
 Assembly language
 High level language
Machine Language

All computers use binary number system that comprise of 0 and 1 for performing internal operations.
The first language available for modern computers was the machine language and it is considered as
the lowest level language. Machine language consists entirely of ONs and OFFs denoted as 1s and 0s
respectively and it varies from one type of machine to another. Since computers are designed to only
understand 0s and 1s, it makes execution of machine language fast because it does not require any
translator.
Although, programs can be written in a number of programming languages but computer only
understands machine language. Therefore, the programs written in other languages need to be
translated to machine language for execution.
The machine language is difficult to read and understand because it is written in binary digits which is
difficult to learn. For example, a program to store a number might be
 1001000101110001 1100101000111011
Machine language is the language of computer and it is also called a first-generation language.
Advantages of Machine Language

1. Program written in machine language executes fast

2. it does not require translator

3. it requires a relatively small space


Disadvantages:

1. it uses binary or Hex code which are difficult for human to read

2. the programs of machine language are difficult to debug and maintain

3. The programmer needs to remember the memory locations of the data

4. Programs written in machine language are difficult to modify because of their complexity

5. The machine language code differs from one type of computer to another.
Assembly Language

Assembly language was introduced in 1952 in order to overcome the limitations of machine language. The assembly language uses
alphanumeric notations instead of binary digits to represent instructions and memory addresses. For example, it uses ADD for addition and
SUB for subtraction.
The alphanumeric code uses a set of letters and numbers to represent instruction. These alphanumeric code and symbols make the program
shorter and easier to write than machine language. The possibility of errors isalso reduced and the program can easily be modified.
An assembly language is also called a second generation language.
Below is a sample of a program written in assembly language to add two numbers:

1. LD AX, 8

2. LD BX, 9

3. ADD AX, BX

4. LD (100), AX

5. JMP BX

6. HLT
From here, AX and BX are registers. These registers are memory locations inside a microprocessor. Every instruction and data need to be
loaded from main memory to registers before the CPU can process it.
Each line of the above program is explained as follows:

1. Loads register AX with the value, 8.

2. Loads BX with the value, 9.

3. Adds the value of register BX to the value of register AX.

4. Stores the value of register AX in the main memory location, 100.

5. Uses JMP to jump to register BX transfer the control to register BX.

6. Stops the program execution.


As we have mentioned earlier, a computer cannot understand any language except machine language.
Because of this, a translation program is needed to interpret assembly language into machine language
code. This translation program is called an assembler. A code written in any programming language other
than machine language is known as source code. This source code requires translation for execution.
Function of an Assembler

Source Code in Object Code in


Assembly Assembler Machine
Language Language

Advantages of Assembly Language:

1. Assembly language programs are easier to write and understand than machine language

2. The programmer can easily remember the opcode and alphanumeric addresses of data
and instruction

3. It saves time in developing and modifying programs in assembly language


Limitations of Assembly Language

1. The execution of programs written in assembly language is slow compare to


those written in machine language

2. Programs written in assembly language depend on processors. Therefore, it


cannot be transported from one machine to another
HIGH LEVEL LANGUAGE

To have proper understanding of machine and assembly languages are known as low-level
languages because of their dependent on machine hardware. In order to create programs that are
hardware independent, a new type of programming language called the high level language was
developed by programmers. A high level language is close to human and it is user-friendly because it
uses natural languages like English language to represent an instruction. It uses words such as PRINT
to print and GOTO to jump to a particular line. Examples of high level language are Basic, COBOL,
and Pascal.
High level language is also known as third-generation language. Each instruction in a high-level
language is translated into multiple machine-level instructions.
Advantages of High-level languages

1. High-level language is easier to learn than machine and assembly language

2. High-level language programs written in one type of computer can easily be used on another
computer because it is machine independent
 It makes reading, writing and maintaining of a program written on high-level language easy
because high-level language vocabularies are similar to English language
Language Translators

Compiler

For you to execute a program written in high-level language, a computer needs translation software called a compiler.
Compiler is a program developed to convert the entire source program in to machine code at once. A compiler is always
language-specific, meaning that each high-level language has its own compiler. Compiler translates the source code of
that language into the object code. For example, compiler for Pascal can only compile the programs written in Pascal. It
cannot compile programs written in any other language, such as COBOL. Once the compiler creates the object program, it
will never use the source program again unless modification is required in the source program. It is this object file that
you normally copy from one computer to another computer for you to install and use.

Interpreter

There are some high-level languages you need to know that use different type of translator program called an
interpreter. Interpreter is a program that converts the source program into a machine code. Instead of creating an
executable file, interpreter translates the source code line– by- line that is what makes it run slowly compared to other
translators.
Debugging of errors is easier using an interpreter because error messages in the interpreter are usually specific and
points out line on which the error occurs.
PERL, BASIC, and Visual Basic languages typically use interpreter.
DIFFERENCES BETWEEN A COMPILER AND AN INTERPRETER

Differences between a Compiler and an Interpreter


S/N
Compiler Interpreter
A compiler translates the entire program first,
An Interpreter translates and executes one line of
1 and generates the object code, which can be
source code at a time
later executed
The object code generated after compilation is
The translated lines of the code cannot be saved
saved for future use. The programmer does not
for future use. therefore, every time code needs to
2 need to compile the program again for object
be translated before execution. This makes the
code generation. This makes the program
program execution slow
execution fast
A compiler detects and shows syntax errors that An interpreter detects and shows errors that relate
3
relate to the entire source code to a line of source code
EXAMPLES OF HIGH LEVEL
LANGUAGE
 BASIC (Beginners All Purpose Symbolic Instruction Code)
 FORTRAN (Formula Translation)
 COBOL ( Common Business Oriented Language )
 PASCAL
 C
B A S IC

Basic was developed in 1964 by Professor John Kenny and Thomas Kurtz at Darmouth College in the USA.
Basicis an interpreter-based language that is easy and simple to use. BASIC was one of the earliest high-level languages to
be implemented on personal computers.

FORTRAN

FORTRAN is one of the oldest high-level languages. It was developed in 1957 by John Backus and his team at International
Business Machines (IBM) Corporation. FORTRAN was designed to solve scientific and engineering problems. After the version
was released, other versions evolved, such as FORTRAN II, FORTRAN IV, and FORTRAN 77. FORTRAN IV was the first language
that was standardized by American National Standards Institute (ANSI).
ANSI is a non-profit making organization, which administers and coordinates standardization and conformity assessment
system in the US.

COBOL

COBOL was initially developed by the mathematician, Grace Hopper, in 1959. It was later modified in 1959-60 by a committee
of the conference on Data Systems Languages (DODASYL). This committee defined the language specifications for COBOL.
 COBOL was standardized by ANSI in 1968. Revised versions of this standard were published in 1974 and 1985, which are
known as COBOL 74 and COBOL 85, respectively. Currently, the latest version of COBOL is known as COBOL 2002. COBOL
was designed to solve business data processing problems
Pascal

Pascal was standardized by ANSI in 1971 by Professor Nicklaus Wirth of the Federal Institute
of Technology in Zurich, Switzerland. He named it after the famous mathematician, Blasé
Pascal.
Pascal was designed to help beginners to learn good problem solving and programming
practices. Today, Pascal is recognized as a language that allows programmers to write
structured and modular programs. It is suitable for scientific as well as business applications.
Pascal was standardized by ANSI in 1983. Since then, different versions of Pascal are also
available.

C Language
C was developed in 1972 by Dennis Ritchie and Brain Kernighan at AT& T’s Bell Laboratories,
USA. The C was designed in such a way that it has features of a high-level language along with
efficiency of low-level language.
C was standardized by ANSI in 1989. C is a compiler-based language. Therefore, C programs
can be easily transferred to other computers equipped with a C compiler. It is widely used for
writing word-processing programs, compilers and operating systems. For example, UNIX
operating system is written in C.
Programming Paradigms it is the processes involved in programming are
usually accompanied by different school of thoughts called programming paradigms. They are the alternative
approaches to programming processes and they also tell us how best we can program a computer. The most
common important programming paradigms are procedural paradigm and the object-oriented paradigm

Procedural Programming

In Procedural programming, a list of instructions is used to tell the computer what to do step-by-
step. Procedural programming relies on procedures, also called subroutines or routines. A
procedure contains a series of computational steps to be carried out. Procedural programming is
also referred to as imperative programming. Examples of procedural languages include FORTRAN,
COBOL and C. If you want a computer to do something, you should provide step-by-step
instructions on how to do it.

Object-Oriented Programming (OOP)

Object-oriented programming is another approach to problem-solving where all computations are


carried out using objects. An object is a component of a program that knows how to perform
certain actions and how to interact with other elements of the program. Objects are the basic units
of object-oriented programming. A simple example of an object would be a person. Logically, you
would expect a person to have a name. This would be considered a property of the person. You
would also expect a person to be able to do something, such as walking. This would be considered
a method of the person. Examples of object-oriented programming are C++, Visual Basic etc.
ALGORITHM
The term algorithm has no root meaning but The concept meaning of algorithm has
come to be accepted as: set of step-by-step instructions for solving a well-defined problem
which takes allowable inputs to produce desired output. These definitions require that an
algorithm must consist of:
1. Set of steps that can be clearly followed (unambiguous), typically by a computer when
implemented in computer language.
2. Executable means that the steps are doable
3. Terminating process means that the process must lead to an end
4. Algorithm takes acceptable data as input.
5. It produces desired output based on the input provided. If wrong input is provided,
algorithm will not give correct output.
One important concept in algorithm is that the problem solver must write explicitly all the
instructions required to solve the problem without assumptions.
In fact, if a problem solver cannot express the concept clearly, the algorithm will not be
useful to solve the problem.
Consider a problem to find the largest of three numbers. Almost anyone can immediately tell
which is the largest, but many cannot explain the steps they followed to arrive at it. Most
people will exclaim, “I just know it! However, an algorithm approach desires the steps to be
clearly and unambiguously stated. This is what separate algorithm from ordinary human
intuition.
The algorithm is stated below.
Step 1 Enter the three numbers say x,y,z.
Step 2 If x>y then go to step 3 else go to step 4
Step 3 is x>z then x is largest go to step 5 else z is largest go to step 5
Step 4 is y>z then y is the largest.
Step 5 stop


Concept of algorithm

Problem definition

Algorithm transformed to computer program that computer executes

Acceptable inputs from user Computer executes the instruction & Desired output
performs specified operations on the input to
produce the desired output
Representing an Algorithm

Algorithms can be represented in different ways, using flowcharts or pseudo codes.


Flowcharts: Flowcharts are graphical representation of algorithms
Pseudo-codes represent algorithms by simple English language.
Characteristics of an Algorithm

i. An algorithm ends after a fixed number of steps


ii. Each step in an algorithm clearly specifies the action to be performed
iii. The steps in an algorithm specify basic operations. These operations could include
mathematical calculations, input/output functions, and logical comparisons
iv. The algorithm should accept input data, in a defined format, before it can be processed by the
given instructions
v. An algorithm generates one or more outputs after the input is processed. The resultant
information termed as output can be displayed or stored for future reference.
Pseudo-Code

Pseudo-code represents an algorithm in the English language. It is used as an alternative


approach to a flowchart. Pseudo-code uses simple statements that are written in a sequential
manner.
Instead of using graphics or table to represent an algorithm, you can also use simple structure
which consists of simple statements called pseudo-code. After you develop pseudo-code, you can
now write it in a programming language. You can easily detect errors when pseudo-code.
The following are a number of key words used in pseudo-code.
 Begin…… end: these are used to start and finish pseudo-code. Begin is the first line and end is
the last line of a pseudo-code.
 Accept: this keyword is used to receive an input from a user.
 Display: This keyword is used to present a result or an input.
 If ……. Else: These keywords are used in decision making. `
Examples of representing algorithm using pseudo-code
1. The following pseudo-code accepts two numbers, calculates the sum of the numbers and display the result:

Begin

Accept the first number

Accept the second number

Calculate the sum of the first number and second number

Display

End

2. The following pseudo-code accepts two numbers and displays the greater number:

Begin:

Accept the second number

Accept the second number

If the first number is greater than the second number

display the “the first number is greater”

else

display “the second number is greater”

end
FLOWCHARTS

 flowchart can be defined as a pictorial representation to solve a problem. In other words, it is a


graphical representation of an algorithm for solving a problem.
 flowchart is used to represent the algorithm in which the steps of processes are shown in various
kinds of boxes that are orderly connected with arrows. Flowchart makes it easy for you to
understand the process of solving a problem. It makes use of standard symbols use to represent
different processes. The most common symbols as approved by the American National
Standards Institute (ANSI) are as shown below:
SYMBOLS NAME MEANING

oval terminal

rectangle process
Symbols Name Meaning

Diamond Decision

parallelogram input/output

circle connector

arrow flow arow

display
Definition of Symbols
 Terminal: This is used to indicate start and end of the chart
 Process: This is the block that contain computational procedures and
analyses
 Input/output: This is used when input is read in and output is produced
 Decision: This is the block where conditions that result in yes or no are put in
 Connector: This is used to join segments of flowchart or where multiple arrow
flows converge in a single point
 Arrow Flow: This is used to indicate the sequence in which the steps described
by the flowchart should be carried out.
 Display: This is used to show the output of an algorithm
APPLICATIONS OF FLOWCHART: flowchart to find
the addition of two numbers
Start

Accept two
numbers

Calculate the
sum of the
two numbers

Display
the Sum

Stop
Flowchart to find the greater of two numbers

start

Accept two
numbers

is number 1 Display
greater than NO "Number 2
number 2 is greater

YES

Display
"Number 1
is greater"

stop
Flowchart for computing the average of two numbers

Start

Accept X
Accept Y

Average
Z= (X+Y)/2

Average
If Z<0 YES is
negative

NO

Display Z

End
The following table shows the pseudo-code keywords with corresponding flowchart symbols

Pseudo-code keywords flowchart symbol

accept

if…..else

begin….end
THANK YOU

You might also like