0% found this document useful (0 votes)
7 views38 pages

3 Computer Program

The document provides an overview of computer programming, covering types of programming languages such as machine, assembly, and high-level languages, along with their advantages and disadvantages. It discusses programming paradigms including structured, object-oriented, and functional programming, as well as type systems like statically and dynamically typed languages. Additionally, it introduces Embedded C as an extension of C for developing micro-controller-based applications, highlighting its significance in embedded systems.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views38 pages

3 Computer Program

The document provides an overview of computer programming, covering types of programming languages such as machine, assembly, and high-level languages, along with their advantages and disadvantages. It discusses programming paradigms including structured, object-oriented, and functional programming, as well as type systems like statically and dynamically typed languages. Additionally, it introduces Embedded C as an extension of C for developing micro-controller-based applications, highlighting its significance in embedded systems.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT I

Computer Programming

[Link]
Faculty Incharge
10/15/2024
2 Agenda

Computer Programming
Types of Programming Language
Program execution
Programming Paradigms
Type Systems in Programming Language
Embedded C

10/15/2024
Computer Programming
3

Computer Program

-Set of instructions for a computer to perform a


task

Computer Programming Language

-Program is written in a language

10/15/2024
Types of Programming Language
4

1. Machine language
2. Assembly language
3. High level language

10/15/2024
Machine Language
5
The computer can understand only machine
language which uses 0’s and 1’s.
Advantages:
Translation free:
Machine language is the only language which the
computer understands. The program written in
machine language can be executed directly on
computer. In this case any conversion process is
not required.
High speed
The machine language program is translation free.
Since the conversion time is saved, the execution
of machine language program is extremely fast.
10/15/2024
Cond…
6
Disadvantage:
 It is hard to find errors in a program written in the
machine language.
Machine dependent: According to architecture used, the
computer differs from each other.
So machine language differs from computer to
computer.
So a program developed for a particular type of
computer may not run on other type of computer.

10/15/2024
Assembly Language
7
To overcome the issues in machine language and
make the programming process easier, an assembly
language is developed
Assembly language is symbolic representation of
machine language.
-uses symbolic notation to represent machine
language instructions.

Assembler
Assembler is the program which translates assembly
language instruction in to a machine language.

10/15/2024
Cond…
8 Disadvantage
Machine dependent
The assembly language program which can be executed
on the machine depends on the architecture of that
computer.
Hard to learn
It is machine dependent, so the programmer should have
the hardware knowledge to create applications using
assembly language.
Less efficient
Execution time of assembly language program is more
than machine language program.
Because assembler is needed to convert from assembly
language to machine language.
10/15/2024
9

10/15/2024
10 High level language

High level language contains English words and


symbols.
The specified rules(syntax) are to be followed
while writing program in high level language.
The interpreter or compilers are used for converting
these programs into machine readable form.

10/15/2024
Cond…
11 Compiler:
Compiler reads the whole program written in high
level language and translates it to machine language.
If any error is found it display error message on the
screen.
Interpreter
 Interpreter translates the high level language program
in line by line manner.
The interpreter translates a high level language
statement in a source program to a machine code and
executes it immediately before translating the next
statement.
When an error is found the execution of the program is
halted and error message is displayed on the screen.
10/15/2024
Advantages
Readability
12
 High level language is closer to natural language so they are
easier to learn and understand
Machine independent
 High level language program have the advantage of being
portable between machines.
Easy debugging
 Easy to find and correct error in high level language
Disadvantages
Less efficient
 The translation process increases the execution time of the
program. Programs in high level language require more memory
and take more execution time to execute.
10/15/2024
13

10/15/2024
Flow of execution of High level
14 program- E.g.: C Program

10/15/2024
1. The C program (source code) firstly, is sent to the
preprocessor. To convert the preprocessor directives into
15
their respective values, the preprocessor is responsible. An
expanded source code is generated by the preprocessor.
2. Then the expanded source code is sent to the compiler
that compiles the code and converts into the assembly code.
3. The assembly code is then sent to the assembler that
assembles the code and converts into the object code. Then,
a [Link] file is generated.
4. The object code is then sent to the linker that links it to
the library like header files. In the next step, it is converted
into an executable code. Then, a [Link] file is
generated.
5. The executable code is then sent to the loader that loads
the code into the memory followed by the execution of the
code. The output is then sent to the console, after execution.
10/15/2024
16

Programming Paradigms
-is all about the writing style and
organizing the program code in a
specific way

10/15/2024
Structured Programming
17 the code will execute the instruction by instruction one after
the other
- the instructions in this approach will be executed in a
serial manner
The structured program mainly consists of three types of
elements:
Selection Statements (if/then/else)
Sequence Statements
Iteration Statements (while and for)
Divide the whole program into modules or functions

Structured paradigm or procedural paradigm instructions are


written in linear blocks or using functions 10/15/2024
Cond…
18

Advantages: (Machine independent)


easy for the programmer to test and debug
easy to do modifications without changing the whole
program
Examples: C, C++, Java
Unstructured programming
Code is written as one block
Examples: BASIC, COBOL, and FORTRAN

10/15/2024
Structured vs Unstructured Programming

Structured Programming is a
19 Unstructured Programming is the
programming paradigm which
paradigm in which the code is
divides the code into modules or
considered as one single block.
function.

Readability

Structured Programming based Unstructured Programming based


programs are easy to read. programs are hard to read.

Modification

It is easy to do changes in It is hard to do modifications in


Structured Programming. Unstructured Programming.

Code Duplication

Structured programming avoids Unstructured programming can have


code duplication. code duplication. 10/15/2024
Object oriented programming
20
language
Object oriented programming is a programming paradigm
based on the concept of classes and objects
E.g: C++, Java, Python

10/15/2024
21

10/15/2024
Functional programming language
22

Functional programming language defines every


computation as a mathematical evaluation.
They focus on the programming languages are
bound to mathematical calculations
Example

10/15/2024
23 Quick Recap

Types of Programming Language


Machine language
Assembly language
High level language

Programming paradigms
Structured programming
Object Oriented programming
Functional programming

10/15/2024
Type Systems in Programming Language
24  A type defines a set of possible values that can be performed
on an variable. Every variable has a type.

Depending on the Timing of Type Checking, there are two types


of language implementations.
Statically typed
Dynamically typed
E.g.:
Statically typed language is C, C++, Java,
Dynamically typed language is Python, Ruby, Javascript etc.
10/15/2024
Cond…
25
Statically typed languages
A language is statically typed if the type of a variable is
known at compile time
all kinds of checking can be done by the compiler, and
therefore a lot of trivial bugs are caught at a very early
stage.
Programs typically perform better at execution time
because type checking has already been completed.
Dynamically typed languages
A language is dynamically typed if the type is associated
with run-time values
variables can receive different values at runtime

10/15/2024
26

10/15/2024
27

10/15/2024
Cond…
28
Depending on whether Implicit Type Conversion
happens or not, there are two types of programming
languages
Strongly Typed language
Weakly Typed language
 Strongly typed language checks the type of a variable
before performing an operation on it, whereas a weakly
typed language does not.
 Strongly typed languages require explicit casts,
while weakly typed languages perform implicit casts.
Weakly-typed languages make conversions
between unrelated types implicitly; whereas, strongly-
typed languages don’t allow implicit conversions
between unrelated types.
10/15/2024
29 Example for
Strongly typed
programming
Example for weakly typed
languages
programming languages include the
• C# following:
• C
• Java • JavaScript
• Perl
• Pascal • PHP
• Python • Ruby
• shell
• TypeScript

10/15/2024
30
Example
Java Code:
int i = 10;
boolean b = true;
[Link](i + b); //compile error. Can't add int with
boolean
Java is a static, strongly typed language
C Code:
int i = 10;
bool b = true;
printf("%d" ,i + b); //Prints 11
C is a static, weakly typed language
10/15/2024
Refer: [Link]
31 Python
var = 21; #type assigned as int at runtime.
var = var + "dot"; #type-error, string and int cannot be concatenated.
print(var);
Python is a dynamic, strongly-typed language

JavaScript
value = 21;
value = value + "dot";
[Link](value);// prints 21dot
JavaScript is a dynamic, weakly-typed language

10/15/2024
32 C Implicit type conversion

10/15/2024
33 C: Explicit type conversion

10/15/2024
34

10/15/2024
Embedded C
35
C is a general-purpose programming language, which
can be used to design any type of desktop-based
application.
Embedded C is an extension of C language and it is
used to develop micro-controller-based applications.
Embedded C is one of the most popular and most
commonly used Programming Languages in the
development of Embedded Systems
An Embedded System is a system which has both the
hardware and software and is designed to do a specific
task. E.g: Washing Machine

10/15/2024
 The microcontroller is designed for a specific task or to
perform the assigned task repeatedly.
36
E.g: Calculator, Washing Machine, ATM machine, Microwave
oven
 The microprocessor contains a CPU. Microprocessors are not
made for a specific task as well as they are useful where tasks
are complex
E.g: Home computers

10/15/2024
37

Microprocessor is part of a microcontroller with


extra memory, I/O ports, and peripherals such as
timer and counters
10/15/2024
Cond…
38 Advantages
It executes a similar task continually so there is no
requirement for changing hardware like additional
memory otherwise storage space.
It executes simply a single task at once
The cost of the hardware used in the embedded c is
typically so much low.
The applications of embedded are extremely
appropriate in industries.
It takes less time to develop an application
program.

10/15/2024

You might also like