You are on page 1of 28

1

Overview of Programming
Languages

03rd February, 2024

ICT172: Principles to Programming


Lecture Notes
Lesson Objectives 2

•By the end of the lesson, student would be able to;


1. Identify the three classes of programming languages.
2. Describe the three classes of programming language.
3. Explain the purpose translators.
4. Describe the model of at least two types of translators.

ICT172: Principles to Programming


Lecture Notes
Introductory Terms

•A program is a set of instructions which is written


following the rules of the chosen language.

•Computer programming (or simply programming)


is the process of writing, testing, debugging, and
maintaining computer programs.

ICT172: Principles to Programming


Lecture Notes 3
Introductory Terms
• A programming language is a computer language made
up of a set of rules and syntax used to write instructions a
computer can understand and execute in order to perform
specific tasks.

• Programming languages are thus used to create


computer programs.
• A programmer is someone who writes computer programs.

• S/he also test and maintain programs or software.

ICT172: Principles to Programming


Lecture Notes 4
Classes of Programming Language
•Different classes of programming
languages have appeared
including:

•Machine language
✓(closer to the computer language)
•Assemble language
✓ (closer to the computer language)
•High-level-language
✓(closer to human languages)

ICT172: Principles to Programming


Lecture Notes 5
Machine Language
•Machine language is the actual (primary) language of the
computer.
•It is a low-level programming language consisting of binary
code that is directly executed by a computer's central
processing unit (CPU).
•Machine languages are the only languages understood
by computers directly without need for translation.
•Each type of CPU (architecture) has its own set of
machine language instructions that it can execute
directly without need for translation.
ICT172: Principles to Programming
Lecture Notes 6
Machine Language
•LOAD Instruction:
Opcode: 0001
Operand: Address in memory (e.g., 0010 for the
address)

0001 0010

•This instruction tells the CPU to load the value from


memory address 0010 into a register.

ICT172: Principles to Programming


Lecture Notes 7
Machine Language
•ADD Instruction:
Opcode: 0010
Operand: Address in memory (e.g., 0011 for the
address)

0010 0011

•This instruction instructs the CPU to add the value at


memory address 0011 to the value in the register.
ICT172: Principles to Programming
Lecture Notes 8
Advantages
1. Machine language does not require any translation,
and hence ensures better machine efficiency.

2. Programs written in machine language run faster.

ICT172: Principles to Programming


Lecture Notes 9
Disadvantages
1.Machine language instructions are very lengthy and
complex.

2.Machine language is not standardized: There is a different


machine language instructions for every type of CPU.
• It is machine dependent

3.It takes more time to program – develop the instructions.

4.It is error-prone and difficult to debug as well.

ICT172: Principles to Programming


Lecture Notes 10
Assembly Languages
•Assembly language was created as an alternative
language to machine language.
•Assembly language is a low-level programming
language that serves as a human-readable
representation of machine code instructions.
•It uses mnemonic codes (short, easy-to-remember
abbreviations) to represent machine instructions and
memory addresses.
•Each assembly language instruction typically
corresponds to one machine language instruction,
providing a more human-readable format.
ICT172: Principles to Programming
Lecture Notes 11
Assembly Languages
• When a programmer uses assembly language to write a
program, he or she can write short mnemonics instead of binary
numbers.
Example:
• mov is the mnemonic for the move instruction.
• add is the mnemonic for the add instruction
• cmp is the mnemonic for the compare instruction.
• add: Add two operands.
• sub: Subtract one operand from another.
• mul: Multiply two operands.
• div: Divide one operand by another.
• inc: Increment the value of an operand.
• dec: Decrement the value of an operand.
ICT172: Principles to Programming
Lecture Notes 12
Assembly Languages
•x86 Assembly Language
The x86 architecture is widely used in personal
computers for:
▪Systems programming such as writing operating
system kernels
▪Writing device drivers
▪Writing embedded systems such as microcontrollers
in appliances.
•ARM Assembly Language
The ARM architecture is commonly used in mobile
devices and embedded systems.
ICT172: Principles to Programming
Lecture Notes 13
Assembler
1.Assembly language programs cannot be directly
executed by the CPU.
2.A special program known as an assembler is required to
translate an assembly language program to a machine
language program.

ICT172: Principles to Programming


Lecture Notes 14
Assembly Language
1. Assembly language basically is a direct substitute for machine
language, and like machine language, it requires that you
know a lot about the CPU.
2. That also means with assembly language you write a large
number of instructions for even the simplest program.
3. Because assembly language is so close in nature to machine
language, it is referred to as a low-level language (LLL).

4. The need to write instructions that are independent of the CPU


type lead to a new generation of programming languages
known as high-level languages (HLL) began to appear.

ICT172: Principles to Programming


Lecture Notes 15
High Level Language
• A high-level language allows the programmer to write
computer code that are machine independent of a particular
type of computer.
• HHL are closer to human languages and further from machine
languages.
• HLL enables arithmetic statements to be written in much the
same way you did in algebra.
• High-level language instructions need to be translated into
machine language before execution.
• HLL programmers are able to create programs without knowing
how the CPU works, and without writing large lines of low-level
instructions.
ICT172: Principles to Programming
Lecture Notes 16
High Level Language
•Advantages
▪High level languages are machine independent,
they are said to be portable.
▪They are easy to read, write and maintain

•Downside
▪Need for translation into machine language
program.

ICT172: Principles to Programming


Lecture Notes 17
High Level Language

•Examples of HLLs ▪C++


are: ▪C#
▪FORTRAN (The first ▪Visual Basic
high-level ▪Java
programming ▪JavaScript
language)
▪Ruby and
▪COBOL
▪Python.
▪Pascal
▪C
ICT172: Principles to Programming
Lecture Notes 18
Comparing the Language Types
Machine Language Assembly language High Level language
Instructions Type Binary codes Mnemonic codes English-like keywords
Translator No Yes Yes
Needed Requires no translator Requires an assembler Requires a compiler or interpreter

Since it is the basic language of


A program called an ‘assembler’ is A program called a compiler or
the computer, it does not require
required to convert the program interpreter is required to convert
any translation, and hence
Time to execute into machine language. Thus, it the program into machine
ensures better machine
takes longer to execute than a language. Thus, it takes more time
efficiency. This means the
machine language program. for a computer to execute
programs run faster.

Simpler to use than machine


Needs a lot of skill, as language, though instruction
Easiest to use. Takes less time to
instructions are very lengthy and codes must be memorized. It
Time to develop develop programs and, hence,
complex. Thus, it takes more takes less time to develop
ensures better program efficiency
time to program programs as compared to
machine language.

ICT172: Principles to Programming


Lecture Notes 19
Comparing the Language Types

Machine Language Assembly language High Level language

Finding and
Prone to error and Prone to error and Easier to find errors.
debugging
error difficult to debug difficult to debug Easier to fix errors.

Machine language
Just like machine Codes written in high-
codes are not portable.
language codes, level are portable/they
Portability They are specific to a
Assembly language can be translated for
particular machine/CPU
codes are not portable. different machine type.
type

ICT172: Principles to Programming


Lecture Notes 20
Identifying the language type

int Num1, Num2


Num1 = 2;
Num2 = 3; High Level Language instructions
Total = Num1 + Num2
cout<<Total<<endl;

LOAD r1, c Assembly language instructions


LOAD r2, d
ADD r1, r2
DIV r1, #2

010101010101001010101 Machine language instructions


0010101010101001111110
100010000101010010100
ICT172: Principles to Programming
Lecture Notes
High Level Language Translators

ICT172: Principles to Programming


Lecture Notes 22
Translator
•Programs that are written in a high-level language
must be translated into machine language.
•A translator is a system program that convert
instructions written in one programming language to
another.

•Depending on the language that a program has


been written in, the programmer will use either of the
following to make the translation:
▪a compiler
▪an interpreter.

ICT172: Principles to Programming


Lecture Notes 23
Compiler
• A compiler is a program that
translates an entire high-level
language program into a cout<< “It a

machine language program.


new day!”;

• The machine language


program can then be
executed any time it is
needed.
• The figure on the right,
illustrates the translation
process using a compiler.

ICT172: Principles to Programming


Lecture Notes 24
Interpreter
• An interpreter, is a program that both
translates and executes the
instructions in a high-level language
program.
cout<< “It a
new day!”;

• As the interpreter reads each


individual instruction in the program, it
converts it to machine language
instructions and then immediately
executes them.
• This process repeats for every
instruction in the program.
• An interpreter does not create a
separate language program because
it combines translation and execution.
ICT172: Principles to Programming
Lecture Notes 25
Differences
Compiler Interpreter
1.Compiler transforms code 1.Interpreter coverts each high-level
written in a high-level program statement, one by one, into
programming language into the the machine code, during program
machine code, at once, before run.
program runs.
2.It takes an entire program as 2.Take a single line of code as input
input 3.Does not generate an intermediate
3.Generates an intermediate code.
code 4.Does not store machine code on
4.Store machine code on the disk. disk at all.
5.Compiled code runs faster. 5.Interpreted code runs slower.
6.Compiler displays all errors after 6.Interpreter displays errors of each
compilation. line one by one.
ICT172: Principles to Programming
Lecture Notes 26
Reading Assignment
•Do a thorough research and reading on the different
programming paradigms and present your finding in a
not less than 2-page MS-Word processed document.

•Submission: Before 5:00pm on Monday, 5th February,


2022.

ICT172: Principles to Programming


Lecture Notes 27
28

End

ICT172: Principles to Programming


Lecture Notes

You might also like