CPF Unit 3
CPF Unit 3
o High-level language
Low-level language
The low-level language is a programming language that
provides no abstraction from hardware and it is
represented in 0 or 1 forms which are machine
instructions. The languages that come in this category
are Machine level language and Assembly language.
Machine-level language
The machine-level language is a language that consists of
a set of instructions that are in the binary form 0 or 1. As
we know that computers can understand only machine
instructions, which are in binary digits, i.e., 0 and 1, so
instructions given to the computer can be only in binary
codes. Creating a program in a machine-level language is
a very difficult task as it is not easy for the programmers
to write the program in machine instructions. It is error-
prone as it is not easy to understand, and its
maintenance is also very high. A machine-level language
is not portable as each computer has its machine
instructions, so if we write a program in one computer
will no longer be valid in another computer.
The different processor architectures use different
machine codes, for example, a PowerPC processor
contains RISC architecture, which requires different code
than intel x86 processor, which has a CISC architecture.
Assembly Language
The assembly language contains some human-readable
commands such as mov, add, sub. The problems which
we face in machine-level language are reduced to some
extent by using extended form of machine-level language
known as assembly language. Since assembly language
instructions are written in English words like mov, add,
sub, so it is easier to write and understand.
Assembly language code is not portable because data is
stored in computer registers and computer has to know
different sets of registers. Computers can only
understand machine-level instructions so we require a
translator that converts assembly code into machine
code. The translator used for translating code is known
as assembler. Machine language provides no abstraction,
assembly language provides less abstraction whereas
high-level language provides a higher level of abstraction.
The machine-level language comes at the lowest The assembly language comes above the machine
level in the hierarchy, so it has zero abstraction language means that it has less abstraction level
level from the hardware. from the hardware.
The machine-level language is written in binary The assembly language is written in simple
digits, i.e., 0 and 1. English language, so it is easily understandable by
the users.
It does not require any translator as the machine In assembly language, the assembler is used to
code is directly executed by the computer. convert the assembly code into machine code.
High-Level Language
The high-level language is a programming language that
allows a programmer to write the programs which are
independent of a particular type of computer. The high-
level languages are considered as high-level because they
are closer to human languages than machine-level
languages. When writing a program in a high-level
language, then the whole attention needs to be paid to
the logic of the problem. A compiler is required to
translate a high-level language into a low-level language.
Commonly used high-level languages
Python Java
C++ C#
Visual Basic JavaScript
It requires the assembler to convert the assembly It requires the compiler to convert the high-level
code into machine code. language instructions into machine code.
The machine code cannot run on all machines, The high-level code can run all the platforms, so it
so it is not a portable language. is a portable language.
Debugging and maintenance are not easier in a Debugging and maintenance are easier in a high-
low-level language. level language.
Compiler
o A compiler is a translator that converts the high-level
Interpreter
An interpreter is also a software program that translates
a source code into a machine language. However, an
interpreter converts high-level programming language
into machine language line-by-line while interpreting
and running the program.
Advantages of Interpreter
An interpreter translates the program line by line.
The interpreter is smaller in size.
Interpreter makes it easier to work with source code.
So it is highly preferred, especially for beginners.
Error localization is easier.
C, C++ Python, Javascript
Assembler
Assembler is a computer system program that is
utilized to convert assembly code into system or
machine code that can be relocated. It is a type of
low-level computer language. It sends instructions
to the processors for various tasks and is unique to
each processor. It is difficult to develop programs in
it because the machine language only consists
of 0s and 1s (Bit format). The assembly language is
similar to a machine language but has a simpler
language and code.
As a result, users require an assembler to translate
assembly code to machine code. It doesn't resolve
all external references in the assembly code during
the code translation. Later, the linker resolves these
references. As a result, it is quite fast at translation.
It creates machine language code in the form of an
executable file. As a result, it required memory for
the storing of this program.
Advantages
1. Control enable developers more control over
their program's hardware and memory layout,
which may be useful for optimizing performance
and accessing low-level system features.
2. Size
It may be smaller in size than programs written in
higher-level languages as they do not utilize libraries
or other support codes.
3. Speed Assembly language programs may run
faster than higher-level language programs as they
are closer to the machine code that the computer
runs and don't need the extra translation steps that
higher-level languages perform.
4. System Portability Assemblers may be more
portable than those programs that are written in
higher-level languages as they do not depend on
specialized libraries or runtime environments.
Disadvantages
1. Complexity Assemblers are difficult to write and
debug because they lack high-level language syntax
to help catch problems.
2. Vulnerability Assembler programs are more
vulnerable to faults and problems than high-level
language programs because they need programmer
to manage low-level features of computer's
architecture manually.
3. Speed These are often slower and less efficient
than high-level language programs that are
compiled into machine code.
4. Execution These are machine-dependent, which
means they may only execute on a certain type of
computer system. It can make it complex to transfer
programs from one system to another.
5. Readability These are frequently more complex
to read and understand than programs that are
written in high-level languages.
PARAMETERS COMPILER INTERPRETER ASSEMBLER
It converts the high- It converts programs
defined programming It also converts the written in the assembly
language into program-developed code language to the
Machine language or into machine language or machine language or
Conversion binary code. binary code. binary code.
Intermediate code
Code generation generation is done in There is no intermediate There is an intermediate
the case of Compiler. code generation. object code generation.
It takes less
execution time An interpreter takes more
comparing to an execution time than the It takes more time than
Execution time interpreter. compiler. the compiler.
Linker
A linker is special program that combines the object files,
generated by compiler/assembler and other pieces of
code to originate an executable file has .exe extension. In
the object file, linker searches and append all libraries
needed for execution of file. It regulates the memory
space that will hold the code from each module. It also
merges two or more separate object programs and
establishes link among them.
Linking is of two types :
1. Static Linking: Static linking is a kind of linking that is
performed during the compilation of a source
program in which linking is performed before the
execution of the file or object. The linker produces a
result at time of copying all library routines into
executable image, which is known as static linking.
Two major tasks performed by static linker are-
o Symbol resolution: In this, each symbol has a
Loader
It is special program that takes input of executable files
from linker, loads it to main memory, and prepares this
code for execution by computer. Loader allocates
memory space to program. It is in charge of loading
programs and libraries in operating system. The
embedded computer systems don’t have loaders. In
them, code is executed through ROM. There are
following various loading schemes:
1. Absolute Loaders
2. Relocating Loaders
3. Direct Linking Loaders
4. Bootstrap Loaders
The loader performs several tasks, including:
Loading: The loader loads the executable file into
Debugging
Debugging is the process of finding and fixing errors or
bugs in the source code of any software. When software
does not work as expected, computer programmers
study the code to determine why any errors occurred.
Types of Errors
Errors refers to issues that occur in a program that
results in unwanted behavior of program. Programming
errors are also known as the bugs or faults, and the
process of removing these bugs is known as debugging.
Some common Types of Errors in Programming are
1.Syntax Error
A syntax error is the most common type of error in
programming. It occurs when the programmer writes
code that is not in accordance with the syntax of the
programming language. Syntax errors are detected by
the compiler, and the compiler reports an error message
to the programmer.
Common examples of syntax errors include
Forgetting to add a semicolon
For example:
1. If we want to declare the variable of type integer,
2. int a; // this is the correct form
3. Int a; // this is an incorrect form.
2.Run-time Error
Sometimes the errors exist during the execution-time
even after the successful compilation known as run-time
errors. A run-time error occurs during execution of a
program. These errors occur when a program tries to
perform an illegal operation. The program compiles
without errors, but when it runs, it encounters an error
that causes it to terminate abnormally. Run-time errors
are often difficult to detect because they do not show up
until the program is executed.
Common examples of syntax errors include
dividing by zero
attempting to access an invalid memory address.
Example - int b=2/0;
3.Linker Error
A linker error occurs when a program references a
function or variable that is not defined in the program or
the libraries it is linked against. Linker errors typically
occur when a program is compiled and linked. The linker
will report an error if it cannot find the necessary files or
libraries to link the program.
Example- The most common linker error that occurs is
that we use Main() instead of main().
4.Logical Error
A logical error occurs when the program compiles and
runs without any syntax, run-time, or linker errors, but
the output is incorrect. These errors occur when the
program's logic or algorithms are incorrect. Logical errors
are challenging to detect because the program does not
generate any error messages.
Example if (a > b) {
cout << "a is less than b";
}
else
{
cout << "b is less than a";
}
5.Semantic Error
Semantic errors are errors that occur when the code
written by the programmer makes no sense to the
compiler, even though it is syntactically correct. They are
different from syntax errors, which indicate errors in the
structure of the program, as semantic errors are related
to the meaning and implementation of the program.
For example,
Using a string instead of an integer or accessing an
Documentation
Any written text, illustrations or video that describe
a software or program to its users is called program
or software document.
At various stages of development multiple
documents may be created for different users. In
fact, software documentation is a critical process in
the overall software development process.
In modular programming documentation becomes
even more important because different modules of
the software are developed by different teams. If
anyone other than the development team wants to
or needs to understand a module, good and detailed
documentation will make the task easier.
Advantages of Documentation
Keeps track of all parts of a software or program
Maintenance is easier
Example Documents
User manual − It describes instructions and
procedures for end users to use the different
features of the software.
Operational manual − It describes all the operations
Structured programming
In structured programming design, programs are broken
into different functions these functions are also known
as modules, subprogram, subroutines and procedures.
Each function is design to do a specific task with its own
data and logic. Information can be passed from one
function to another function through parameters. Many
high level languages supported structure programming.
Structured programming minimized the chances of the
function affecting another. It supported to write clearer
programs. Its organization helped to understand the
programming logic easily. So that one can easily
understand the logic behind the programs. It also helps
the new comers of any industrial technology company to
understand the programs created by their senior workers
of the industry. It also made debugging easier.
Functional abstraction was introduced with structured
programming. Abstraction simply means that how able
one can or we can say that it means the ability to look at
something without knowing about its inner details. In
structured programming, it is important to know that a
given function satisfies its requirement and performs a
specific task, how that task is performed is not
important.
Bottom-up Approach
The bottom-up approach is development strategy that
involves breaking down a complex system into smaller,
more manageable components, and then building those
components up into a larger, more comprehensive
program. At the heart of the bottom-up approach is the
idea of modularization, which involves dividing a
program into smaller, self-contained units that can be
developed and tested independently of one another.
Each module should have a well-defined interface that
specifies how it interacts with other modules in the
system, and it should be implemented in such a way that
it can be reused in other programs or projects.
Advantages
Modular Design: This approach allows programmers to
design and implement individual components that are
modular and reusable. This makes code more flexible and
easier to maintain, as changes can be made to individual
components without affecting the entire program.
Faster Development: This approach enables faster
development times as individual components can be
developed in parallel by different team members.
Because each component is designed and tested
separately, the changes to one component will not
impact other components in the program.
Early Testing: The bottom-up approach facilitates early
testing of individual components, allowing errors to be
caught and corrected early in development cycle. This
makes the testing process more efficient and reduces the
cost of fixing errors later in the development cycle.
Incremental Integration: This enables incremental
integration of individual components, making it easier to
detect and correct errors as they arise. This approach
reduces the risk of errors being missed until the entire
program is complete, making it more difficult and costly
to correct them.
Disadvantages:
Lack of Overview: The bottom-up approach does not
provide overview of entire system from the beginning.
This may result in overlooking some high-level
requirements, leading to incomplete or incorrect system
functionality.
Time-consuming: The bottom-up approach requires
more time in the initial stages of development to identify
and develop individual components. This can lead to
longer development times for smaller programs.
Difficulty in Design: The bottom-up approach can be
challenging to design and implement if the individual
components are complex and have a large number of
dependencies. This can make the process of integrating
components more difficult and time-consuming.
Top-Down Approach
A top-down approach is a programming methodology
that involves starting with an overview of the problem,
breaking it down into smaller sub-problems, and then
gradually building the solution by implementing each
sub-problem in a hierarchical manner. The top-down
approach starts with a high-level view of the program
and then works downwards to implement the individual
components.
The problem is broken down into smaller parts, and each
part is solved separately, then combined to form the
complete solution.
The top-down approach is often used in large projects
because it helps to manage complexity by organizing the
code into logical units that can be developed, tested, and
integrated independently. In a top-down approach, the
first step is to identify the problem and understand its
requirements. This involves analysing the problem
statement and determining the inputs and outputs
required by the program. Once the problem is clearly
defined, the next step is to break it down into smaller,
more manageable sub-problems.
For example, let's say we are tasked with building a
program to calculate the average temperature of a city.
In a top-down approach, we would start by breaking
down the problem into smaller parts, such as:
o Collecting temperature data from various sources
Advantages:
Modularity: This approach promotes modularity by
breaking down a problem into smaller sub-problems.
This makes it easier to maintain, test and modify the
code since each module can be developed and tested
independently.
Reusability: This approach also promotes reusability
since common patterns and solutions can be identified
and reused in other parts of the program.
Parallel Development: Since different developers can
work on different modules of program simultaneously,
parallel development is possible, which can significantly
reduce the development time and increase productivity.
Clear understanding of the problem: The top-down
approach helps to develop a clear understanding of the
problem and its requirements before starting the
implementation, which helps to ensure that the program
meets the user's needs.
Disadvantages:
Difficulty in predicting design upfront: The top-down
approach can be challenging to predict the design of the
program upfront since new requirements may arise
during implementation that may require modifications to
the original design.
Integration issues: As each sub-problem is developed
independently, it can be challenging to integrate the
different parts of program. This requires careful planning
and testing to ensure that program works as expected.
Oversimplification of the problem: Breaking down a
problem into smaller sub-problems can sometimes
oversimplify the problem, leading to a less effective
solution.
Increased complexity: As the number of modules in the
program increases, the complexity of the program also
increases. This can make it difficult to manage and
maintain the code.