This document provides an introduction to programming languages. It defines programming as a sequence of steps to solve a problem and explains why learning to program is important for developing problem solving skills. It then describes the main types of programming languages - low-level languages like machine language and assembly language that are close to hardware, and high-level languages that are more abstract and English-like. It also discusses the concepts of source code, object code, and language translators like assemblers, interpreters, and compilers that convert source code into executable object code.
1. Intro to Programming Languages Intro to Programming
MUHAMMAD HAMMAD WASEEM 1
What Is Programming:
As this course is titled “Introduction to Programming”, therefore it is most essential and
appropriate to understand what programming really means and what its basic fundamentals are. Let us
first see a widely known definition of programming.
"A program is a precise sequence of steps to solve a particular problem.”
It means that when we say that we have a program, it actually mean that we know about a
complete set activities to be performed in a particular order. The purpose of these activities is to solve a
given problem.
Why Programming Is Important:
Learning to programming is important because it develops analytical and problem solving
abilities. It is a creative activity and provides us a mean to express abstract ideas. Thus programming is
fun and is much more than a vocational skill. By designing programs, we learn many skills that are
important for all professions. These skills can be summarized as:
Critical reading
Analytical thinking
Creative synthesis
Programming Languages:
A set of words and symbols used to write programs is called Programming Language.
Programmers write instructions in various programming languages, some directly understandable by
computers and others requiring intermediate translation steps. A programming language is a mean of
communication between a user and computer. Hundreds of computer languages are in use today. There
are two major types of programming languages. These are
Low Level Languages
High Level Languages.
Low Level Languages
Low-level languages are near to computer hardware and far from human languages. Low Level
languages are further divided into: Machine languages & Assembly languages
Machine language
Any computer can directly understand only its own language (Machine Language). Machine
language is the "natural/native language" of a computer and as such is defined by its hardware
design.
Machine languages generally consist of strings of numbers (ultimately reduced to 1s and 0s) that
instruct computers to perform their most elementary operations one at a time.
• E.g. a program instruction may look like this: 1011000111101
Machine languages are machine dependent.
[Note: Machine language is often referred to as object code. This term predates "object-oriented programming."]
Advantage
Machine language run very fast because no translation program is required for the CPU.
2. Intro to Programming Languages Intro to Programming
MUHAMMAD HAMMAD WASEEM 2
Disadvantages
It is very difficult to program in machine language. The programmer has to know details of
hardware to write program.
Programmer has to remember a lot of codes to write a program which results in program errors.
It is difficult to debug the program.
Assembly languages
Machine-language programming was simply too slow, boring and error-prone for most
programmers.
Instead of using the strings of numbers that computers could directly understand, programmers
began using English-like abbreviations to represent elementary operations.
These abbreviations formed the basis of assembly languages and called mnemonics (Pronounced
as: Ne-Monics).
Translator programs called assemblers were developed to convert early assembly-language
programs to machine language at computer speeds.
o The following section of an assembly-language program adds overtime pay to base pay
and stores the result in gross pay:
load basepay
add overpay
store grosspay
Although such code is clearer to humans, it is incomprehensible to computers until translated to
machine language.
Mostly used to write system software.
Advantages:
The symbolic programming of Assembly Language is easier to understand and saves a lot of time
and effort of the programmer.
It is easier to correct errors and modify program instructions.
Assembly Language has the same efficiency of execution as the machine level language. Because
this is one-to-one translator between assembly language program and its corresponding machine
language program.
Disadvantages:
One of the major disadvantages is that assembly language is machine dependent. A program
written for one computer might not run in other computers with different hardware
configuration.
High-level languages
Computer usage increased rapidly with the advent of assembly languages, but programmers still
had to use many instructions to accomplish even the simplest tasks.
To speed the programming process, high-level languages were developed in which single
statements could be written to accomplish substantial tasks.
Translator programs called compilers convert HLL programs into machine language.
High-level languages allow programmers to write instructions that look almost like every day
English and contain commonly used mathematical notations.
A payroll program written in a high-level language might contain a statement such as:
3. Intro to Programming Languages Intro to Programming
MUHAMMAD HAMMAD WASEEM 3
o grossPay = basePay + overTimePay;
Advantages of High Level Languages
Higher level languages have a major advantage over machine and assembly languages that higher
level languages are easy to learn and use. It is because that they are similar to the languages
used by us in our day to day life.
Easy error detection.
Machine independence
Deep hardware knowledge not required.
Concept of Source and Object Code:
Source Code:
A program written in a high level language is called source code. It is also called source program.
It cannot be executed by computer directly, it is converted into object code and then executed.
Object Code:
A program in machine language is called object code. It is also called object program or machine
code. Computer understands object code directly.
Concept of Language Translators:
Computer understand only machine language. A program written in high level or assembly language
cannot be run on a computer directly. It must be converted into machine language before execution.
Language processor or translator is a type of system software that converts these programs into
machine language. Every computer language has its own translators.
Types of translators:
Assembler:
An assembler is a translating program that translates the instruction of assembly language into
machine language.
Interpreter:
It is a program that converts one statement of a program into machine at one time. It executes a
statement before translating the next statement of source program. If there is an error in the
statements, interpreter stops working and displays an errors message.
The advantage of interpreters over compiler is that an error is found immediately. So the
programmer can correct errors during program development.
The disadvantage of interpreter is that it is not very efficient. The interpreter does not produce an
object program. It must convert the program each time it is executed.
Compiler:
A compiler is a program that converts the instruction of a high level language (source) program
into machine language (object program) as a whole. The object program can be executed many times.
The compiler checks each statement in the source program and generates machine instructions.
Compiler also checks syntax errors in program. A source program containing an error cannot be
compiled. A compiler can translate the programs of only those languages for which it is written.