0% found this document useful (0 votes)
14 views54 pages

Introduction to Computer Programming

The document provides an overview of computers, programming, and programming languages, explaining the computer information processing cycle and the distinction between system and application software. It details the different levels of programming languages, including machine, assembly, and high-level languages, along with their advantages and disadvantages. Additionally, it covers the concepts of syntax, semantics, compilers, and the execution of programs.

Uploaded by

masachibwatoh
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)
14 views54 pages

Introduction to Computer Programming

The document provides an overview of computers, programming, and programming languages, explaining the computer information processing cycle and the distinction between system and application software. It details the different levels of programming languages, including machine, assembly, and high-level languages, along with their advantages and disadvantages. Additionally, it covers the concepts of syntax, semantics, compilers, and the execution of programs.

Uploaded by

masachibwatoh
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

UNIT2 COMPUTER

PROGRAMMING

LESSON1
What is a Computer?
An electronic device that:
• accepts data (input),
• manipulates the data
(process),
• provides output (output) and
• stores the results (storage).
HE COMPUTER INFORMATION
ROCESSING CYCLE
Input c l
C y
ng
s i
e s
c
Output
P ro Process
on
ti
a
r m
Memory/Storage
f o
In
COMPUTER
PROGRAMMING?
Is the process of developing and
implementing various sets of
instructions to enable a computer
to do a certain task.

These instructions are considered


computer programs and help the
computer to operate smoothly.
WHAT IS A COMPUTER
PROGRAM?
A computer program is a
sequence of instructions
written using a Computer
Programming Language
to perform a specified
task by the computer.
WHAT IS A Computer
Program?
A computer program is a collection
of step-by-step instructions that tell
the computer how to perform a
particular task or group of related
tasks.
PROGRAM IS ALSO KNOWN AS

SOFTWARE
MAIN TYPES OF
Software(PROGRAMS)
There are two general types
of software.
•System software &
•Application software
SYSTEM SOFTWARE:
Operating Systems
The two operating systems most
users encounter are Microsoft
Windows and Mac OS X.

Operating systems contain the


instructions that allow the parts of a
computer to work together by
performing most, if not all, of the
“behind the scenes” tasks such
SYSTEM SOFTWARE:
Device
Device Drivers
drivers contain the
instructions which tell the computer
how to interact with that particular
device.
Many device drivers come
preinstalled on the operating
system but devices such as printers
and scanners come with a device
driver to install on the computer if
necessary.
Application Software
Software the computer uses to
carry out a specific task as specified
by the user.
Word Processing
Software that enables the user to
enter, edit, format and print
documents containing primarily, but
not limited to text.
Spreadsheets
Software that enables the user to
enter, edit, format, print, sort and
calculate primarily numeric data.
Computer Programming Languages:

A programming language is an
artificial language that can be used to
control the behavior of a machine,
particularly a computer.

 Programming languages, like human languages,


are defined through the use of syntactic and
semantic rules, to determine structure and
meaning respectively.
Computer Programming Languages:
A PL is
A special purpose and limited
language
A set of rules and symbols
used to construct a
computer program
A language used to interact
with the computer
Computer Programming Languages
(Contd…):

Programming languages
are used to facilitate
communication about the
task of organizing and
manipulating information,
and to express algorithms
precisely.
Computer Programming Languages
(Contd…): binary form
In order for a computer to be able to execute a
program, the program must first be present in
binary form within the computer's memory.

However, writing a program directly in binary


form is completely out of the question.

 The solution to this conflict is for the


programmer to write a program in a more
suitable language and then to use a special
computer program to translate it into the binary
machine code necessary for the target computer.
Levels of Programming
Languages

Programming languages are


said to be "lower" or "higher,"
depending on how close they
are to the language the
computer itself uses (Os and 1s
= low) or to the language
people use (more English-like-
high).
Levels of Programming
Languages
We will consider five levels of language.
In terms of ease of use and capabilities,
each generation is an improvement over its
predecessors.
The five generations of languages are:
Machine language
Assembly languages
High-level languages
Very high-level languages
Natural languages
Machine Languages, Assembly
Languages, and High-level Languages
 Three types of
programming languages
Machine languages
Strings of numbers giving
machine specific instructions
Example:
+1300042774 (these would really
be in binary)
+1400593419
+1200274027
20
 2000 Prentice Hall, Inc. All rights
Machine language:
 While easily understood by computers,
machine languages are almost impossible for
humans to use because they consist entirely of
numbers.

For example, an x86/IA-32 processor can


execute the following binary instruction as
expressed in machine language:

Binary: 10110000 01100001 (Hexadecimal: 0xb061)


Machine language:
A computer is a binary machine.

The signals used by the various parts of the


machine to communicate with each other
must be in binary form.
A program shown in binary form (or in hex
for ease of reading) so as to reflect these
values is said to be in machine language.

Machine language is the most basic and
elementary form in which any program can
exist
Machine Language :
Machine Language is the only language that is
directly understood by the computer.
 It does not need any translator program.
 We also call it machine code and it is written as
strings of 1's (one) and 0’s (zero).
 When this sequence of codes is fed to the
computer, it recognizes the codes and converts it
in to electrical signals needed to run it. For
example, a program instruction may look like this:

1011000111101
Advantage Machine
Language :

The only advantage is that


program of machine
language run very fast
because no translation
program is required for the
CPU.
Disadvantages Machine
Language:
1. It is very difficult to program in machine
language.

The programmer has to know details of


hardware to write program.

2. The programmer has to remember a lot


of codes to write a program which results in
program errors.

3. It is difficult to debug the program.


Assembly Level Language:
An assembly language is a low-level
language for programming computers.

The word "low" does not imply that the


language is inferior to high-level
programming languages but rather
refers to the small or nonexistent
amount of abstraction between the
language and machine language,
because of this, low-level languages are
sometimes described as being "close to
the hardware."

It implements a symbolic representation


of the numeric machine codes and other
Levels of Programming
Languages
Assembly languages
English-like abbreviations
representing elementary
computer operations
(translated via assemblers)
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
Assembly Level
Language (contd…):
 A utility program called an assembler, is used to
translate assembly language statements into the
target computer's machine code.

 The assembler performs a more or less isomorphic
translation (a one-to-one mapping) from mnemonic
statements into machine instructions and data.
Example: Assembly language representation is
easier to remember (more mnemonic)

mov al, 061h

This instruction means:


Move the hexadecimal value 61 (97 decimal) into
the processor register named "al".

The mnemonic "mov" is an operation code or


opcode, A comma-separated list of arguments or
Assembly Language
A symbolic representation of the machine
language of a specific processor.
 Is converted to machine code by an assembler.
 Usually, each line of assembly code produces one
machine instruction (One-to-one correspondence).
 Programming in assembly language is slow and
error-prone but is more efficient in terms of
hardware performance.
 Mnemonic representation of the instructions and
data
 Example:
Load Price
Add Tax
Store Cost
Example (Adds 2 numbers):

name "add"
mov al, 5 ; bin=00000101b
mov bl, 10 ; hex=0ah or bin=00001010b
add bl, al ; 5 + 10 = 15 (decimal) or
hex=0fh or

bin=00001111b
Advantages Assembly
Language:

[Link] symbolic programming of Assembly Language is easier
to understand and saves a lot of time and effort of the
programmer.

[Link] is easier to correct errors and modify program instructions.

[Link] 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 Assembly
Language:

[Link] 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
Machine Languages, Assembly
Languages, and High-level Languages
High-level languages
Instructions closer to everyday English
 English is a natural language. Although high
level programming languages are closer to
natural languages, it is difficult to get too
close due to the ambiguities in natural
languages (a statement in English can mean
different things to different people –
obviously that is unacceptable for computer
programming).
Use mathematical notations (translated
via compilers)
Example:
grossPay = basePay + overTimePay

33
High-level language
A programming language which use
statements consisting of English-like keywords
such as "FOR", "PRINT" or “IF“, ... etc.
 Each statement corresponds to several
machine language instructions (one-to-many
correspondence).
 Much easier to program than in assembly
language.
 Data are referenced using descriptive names
 Operations can be described using familiar
symbols
 Example:
Cost := Price + Tax
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.
Advantages of High Level
Languages
High-level language programs are
portable.
(Although some programs could
still have a few machine-dependent
details, they can be used with little
or no modifications on other types
of machines.)
Program development is faster
Fewer lines of code
Program maintenance is easier
Low vs High level language

Low Level Language:


The Low Level language are those
languages which are near to computer
language.
It is hard to understand by Human and easy
to understand by Computer itself.

Example:
Machine Language (1's and 0's)
Assembly Language (Key words and
symbols)
Advantages and Disadvantages
of Low Level Languages:

It consists of binary digits and some symbols.


It depends on machine.
Machine language directly executes on
computer.
No need of language translator for machine
language.
Program written in low level language is
called object code.
Example of low level languages
are “MACHINE” and “ASSEMBLY” Language.
disadvantages of Low Level languages

It is not easy to
understand.
It is difficult to
modify.
High Level Languages:

The high level languages which are close to human languages.
 they are easy to understand by Humans but difficult for
Computers to understand.
 Computer needs some mechanism to understand them.
Example:

 BASIC
 PASCAL
 FORTRAN
 C/C++
 python
 JAVA etc.
Advantages and disadvantages of
High Level Languages
advantages of high level languages:
they are close to human being
they are easy to understand
They consist of English language like
structure
 It does not depend upon machine
they are easy to modify
disadvantages of high level languages:
they need language translator to translate
into program in to machine language.
They do not execute directly on computer.
Programming Language levels
summary:
•.

•Machine languages are the only languages


understood by computers.
Programming Language levels
summary:Computer Languages
– Machine Language
• Uses binary code
• Machine-dependent
• Not portable
Assembly Language
Uses mnemonics
Machine-dependent
Not usually portable
High-Level Language (HLL)
Uses English-like language
Machine independent
Portable (but must be compiled for different
platforms)
Examples: Pascal, C, C++, Java, Fortran, . . .
Syntax & Semantics in
programming
Syntax:
A language's syntax is the
grammar of the language.
Semantics:
The meanings of words
and symbols used in the
language
Compilers & Programs
Source code or Source program
The form in which a computer
program, written in some formal
programming language, is
written by the programmer.

 Can be compiled automatically


into object code or machine code
or executed by an interpreter.
Compilers & Programs
Compiler
A program that converts
another program from
some source language (or
high-level programming
language / HLL) to machine
language (object code).
Compilation into Assembly L

Source Assembly
Program Compiler Language

Assembly Assembler Machine


Language Language
Compilers & Programs
Object code or Object program
Output from the compiler
Equivalent machine language translation of the
source program
Files usually have extension ‘.obj’

Executable program
Output from linker/loader
Machine language program linked with necessary
libraries & other files
Files usually have extension ‘.exe’
Program Execution
 Steps taken by the CPU to run a program
(instructions are in machine language):
1. Fetch an instruction
2. Decode (interpret) the instruction
3. Retrieve data, if needed
4. Execute (perform) actual processing
5. Store the results, if needed
Program Errors
Syntax Errors:
Errors in grammar of the language
Runtime error:
When there are no syntax errors, but the
program can’t complete execution
 Divide by zero
 Invalid input data

Logical errors:
The program completes execution, but delivers
incorrect results
Incorrect usage of parentheses
Compilation
Source Target
Program Compiler Program

Input Target Program Output

 Compiler translates source into target (a machine


language program)
 Compiler goes away at execution time
 Compiler is itself a machine language program,
presumably created by compiling some other
high-level program
 Machine language, when written in a format
understood by the OS is object code
Interpretation
Source
Program

Interpreter Output

Input

• The interpreter stays around during


execution
• It reads and executes statements one at a
time
Compilation vs. Interpretation
Compilation:
Syntax errors caught before running the
program
Better performance
Decisions made once, at compile time
Interpretation:
Better diagnostics (error messages)
More flexibility
Supports late binding (delaying decisions
about program implementation until runtime)
 Can better cope with PLs where type and size of
variables depend on input
Supports creation/modification of program
code on the fly (e.g. Lisp, Prolog)
JAVA
For portability:

Java Compiler

bytecode

ML Interpreter

For flexibility: Just In Time (JIT) compiler


translates bytecode into ML just before
execution

Common questions

Powered by AI

Programming languages vary across several levels with distinctive characteristics. Machine languages consist entirely of binary code and are the most basic form of instructions directly understood by computers . Assembly languages provide a symbolic representation of machine language, using mnemonics and offering a one-to-one mapping to machine instructions . High-level languages, like C++ or Java, resemble natural language with abstract data types and more complex functionality, allowing for one-to-many correspondence of compiled instructions . Very high-level languages and natural languages, like SQL or natural language processing languages, are structured even closer to human communication, focusing on specificity and ease of use but requiring robust translation into executable code . Each level progressively abstracts the machine details to increase ease of use for human programmers .

High-level languages are considered more advantageous for most application development projects because they are easier to learn and use, resembling human languages more closely . They simplify programming by abstracting complex hardware details, thus allowing developers to focus on implementing logic and features without needing to manage low-level operations . High-level languages also enhance code readability and maintainability, making it easier to collaborate across teams and adapt to new requirements . Furthermore, their portability allows developers to run the same code on different systems with little or no modification, which is critical for broad software deployment .

High-level programming languages are designed to be easier for humans to read and write, resembling natural language more closely than low-level languages . They are portable and do not rely on machine-specific instructions, making it easier to transfer programs across different systems with minimal changes . However, high-level languages require a compiler or interpreter to translate the code into machine language before execution, which can introduce overhead and require more runtime resources . In contrast, low-level languages, such as machine and assembly languages, are closer to the hardware and therefore more efficient in terms of performance . They execute directly on the computer without a need for translation, which allows for faster program execution . However, they are much more difficult to learn and troubleshoot due to their complexity and machine dependence .

Syntax in a programming language refers to the grammar rules that define the way in which programs are written . Syntax ensures that the code is structured correctly to be understood and processed by compilers or interpreters . Semantics, on the other hand, deals with the meaning of the expressions within the code . Both syntax and semantics are crucial because while syntax ensures the correct form, semantics ensures the code performs the intended operations and results in meaningful outcomes . Without proper syntax, the code would fail to run, and without semantics, the code could run but produce erroneous results, thus both are critical for creating reliable and functional programs .

Machine language directly executes on the computer processor without requiring any translation, which results in very fast execution . This direct execution is the primary advantage as it allows programs to run efficiently and utilize hardware capabilities fully . However, the disadvantages include its difficulty to program and debug, as it consists entirely of binary digits (1s and 0s), which are unintelligible to humans . This complexity makes it error-prone and requires profound knowledge of the hardware, leading to a higher likelihood of programming errors .

An assembler translates assembly language, which consists of mnemonics, into machine language (one-to-one correspondence). It directly converts symbolic code into binary code that a computer can execute without further translation . A compiler, on the other hand, translates high-level language source code into machine language (object code). It processes entire programs, checking for syntax errors before converting the code into executable programs . The output of an assembler is machine-specific machine language instructions, while the output of a compiler is typically object code or a complete executable file after linking .

A programmer might elect to use a low-level programming language in scenarios where performance is critical and where direct interaction with hardware is necessary . This includes tasks like developing operating systems, device drivers, and embedded systems where efficiency and speed are paramount . Low-level languages like assembly language provide precise control over system resources and processing power, which is vital for highly performance-sensitive applications . Additionally, for systems that do not require portability across different hardware architectures, the close-to-hardware nature of low-level languages offers significant advantages in optimizing execution by minimizing overhead associated with higher-level abstractions .

Device drivers serve as critical components of system software that allow the operating system to communicate with hardware peripherals . They provide the necessary instructions for the system to interact correctly with devices like printers and scanners, ensuring smooth operation across the computer's ecosystem . Many device drivers come pre-installed with the operating system, which highlights their role in maintaining hardware compatibility and efficiency from installation . By translating commands into a language that the hardware understands, device drivers exemplify the behind-the-scenes task of system software in managing and executing complex tasks seamlessly within a computing environment .

Common types of programming errors include syntax errors, runtime errors, and logical errors . Syntax errors occur when the code violates the grammatical rules of the programming language, often caught by the compiler or interpreter before the program runs . Runtime errors happen when the program encounters an unexpected situation during execution, such as dividing by zero, causing the execution to halt unexpectedly . Logical errors occur when the program runs successfully but produces incorrect results due to mistaken program logic or incorrect algorithm implementation . Each type of error presents challenges in the development process, from halting development due to syntax errors, requiring debugging for runtime errors, and demanding critical algorithm checks for logical errors, all impacting the efficiency and correctness of software output .

Interpretation and compilation are two distinct methods of executing programs. Compilation involves translating the entire high-level program into machine language before execution, catching syntax errors beforehand, and typically offering better performance since the compilation step is done once . In contrast, interpretation translates program instructions on-the-fly during execution, leading to typically slower performance but providing better diagnostics and greater flexibility, such as the ability to modify code during execution . Practically, this means that interpreted languages can be more suitable for dynamic and scripting tasks where runtime adaptation is needed, while compiled languages are preferable for applications requiring optimized performance and security .

You might also like