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

ICS 2102 Lecture 1 Hardware and Software Basics

Uploaded by

naffarm74
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)
33 views38 pages

ICS 2102 Lecture 1 Hardware and Software Basics

Uploaded by

naffarm74
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
You are on page 1/ 38

ICS 2102: Introduction to

Computer Programming

ICS 2102-Lecture 1: Hardware and


Software Basics
In Today’s world…
• Computers are indispensable
• They are more complex than ever before
• Moore’s law- The power and complexity of
computer doubles every 15-18 months
• Hence need to design efficient and robust
software
HARDWARE
• Computer Organization
• Computer consists of:
- CPU(Central processing Unit)
- Main Memory
- I/O devices
- Bus
RAM, CPU, Bus
Memory
CPU (RAM)

Registers

Address
bus Data
bus Memory
(ROM)
1-4
Computer Organization
• CPU (processor) – brain of the computer.
It’s function is to execute programs stored
in Main memory by fetching them,
examining them and executing them
• CPU consists of:
- Control Unit (Instruction fetch)
- Arithmetic Logic Unit (Calculations)
- Registers (high speed memory units)
Computer Organization…contd.
• How are instructions processed?
• The control Unit:
- fetches the instruction and decodes it, and
sends control signals to the other units
- Arithmetic Logic Unit performs
calculations on the data
Memory
• What is memory?
• A place for storing data and programs.
• There are 3 types of memory:
- Internal (within CPU..like registers)
- Primary (fats..RAM)
- Secondary (slow, but large capacity..Disk)
Functionality of the RAM (Memory)
• Structure of the Memory (RAM)
• The RAM consists of multiple memory cells:

• Each memory cell is uniquely identified by its memory


address
• Memory addresses always starts at zero (0)
• The last memory address depends on the amount of
memory installed in the computer system
Operation of the memory
• Memory can store and recall (retrieve) values for the
CPU:
Each memory cell can store one number
Example:

In this example:
• Memory location 0 stores the value 13
• Memory location 1 stores the value 3
• Memory location 2 stores the value 0
• Memory location 3 stores the value 45
• ...
I/O Devices
• What is an I/O device?
• Purpose is to transfer information between
CPU and outside world
• Egs. Keyboard, mouse, printer
BUS
• What is a BUS?
• A set of parallel wires that can carry several
bits at a time.
• It carries instructions, data, address or
command
• 3 types: Data Bus, Address Bus, Control
Bus.
Software:
Instructing a computer to execute a
• command
A computer is the ideal machine to execute computational
algorithms because:
• The computer can perform arithmetic operations
• It can also perform an operation only when some
condition is satisfied (using the conditional branch
instruction)
• Problem

• We (a human) has to tell (communicate) the


computer what steps to do in machine language

Humans are not good in machine languages


SOFTWARE
• What is Software?
• A set of programs.
• In the earlier days, programs were written
in 0’s and 1’s. (machine language, or Low
Level Programming)
• Disadvantage: Very cumbersome, and
debugging becomes a problem.
SOFTWARE..contd.
• Remedy?
• Using mnemonics. This was called
Assembly Language Programming (ALP)
• E.g. MOV AX, BX
• But this needed a translator to convert AL to
ML. This translator was called Assembler.
SOFTWARE..contd.
• Disadvantage of AL and ML?
• They were not portable. I.e., once written, they
were good only for that machine. Machine
Specific.
• Remedy?
• Develop a language that is machine independent,
and has more powerful features to suit specific
needs .
SOFTWARE..contd.
• High Level Languages
• These have the following features:
• Machine Independence
• Very good debugging facility
• Good documentation
• Compact: 1 instruction in a HLL corresponds to
several in ALL or LLL
SOFTWARE..contd.
• High Level Languages meet specific needs such as
business, scientific etc.
• HLL’s come with their own translators, known as
Compilers or Interpreters, and other software
called Linkers, Loaders, Debuggers and Libraries.
• Compilers convert the source code to object code,
which is in machine language.
SOFTWARE..contd.
• How are HLL programs executed?
• Compiler/Interpreter translates the source
code.
• The Loader, which is software, loads the
object code into main memory.
• The Linker links external files used by the
current file.
SOFTWARE..contd.
• The editor, compiler, library, linker, loader,
debugger can be integrated into one environment
called the IDE, or Integrated Development
Environment. MS Visual Studio is an e.g.
• Compiler/Interpreter translates the source code.
• The Library is a catalogue of predefined, compiled
and tested functions. These contain geometric ,
arithmetic and other commonly used functions.
• Users can build their own library functions.
SOFTWARE..contd.
• Programs are broadly divided into 2 categories:
• Systems programs, which direct the internal
operations of the computer.
• E.g. Linker, Loader, Compiler
• Applications Program, which solve user-oriented
problems
• E.g. payroll software, banking software.
3 types of translators: Assembler, Compiler, and Interpreter
• Computers can only read their machine languages, so translators are required to convert
programs into machine codes.(ML)

Assembler:
• A special program that reads a text file with assembly instructions and converts them into
machine codes.

Compiler:
• A special program that converts the statements written in a high-level programming language
and turns them into machine codes.
• Typically, we type program code using an editor (eg. Microsoft Visual Studio).
The editor often has an Integrated Development Environment (IDE), which contains a
compiler.
• The file written by the programmer is called the source program.
circle.c, square.c, etc.
• A program may be composed of several source programs, eg. each stores some functions.
Each source program is compiled to form an object file (containing the machine codes).
The object files are then linked to form the final executable file. circle.obj, square.obj, etc
.
shape.exe
The whole process is called building (including compilation and linking).
Interpreter
• A special program that translates and executes each source statement at run-time,
before translating and executing the next statement.
• Example: the web page browsers.
• A program that relies on an interpreter to translate and run is called a script.
The language is called scripting language.

Advantage of using interpreters (eg. for html / javascript)


• After typing the source code, we can run the program at once.
Do not need to compile the whole source code into an executable file first.
• If the language is recognized by webpage browsers, then it is very portable.

Advantage of using compilers (eg. for c, c++, java)


• No source program is required during the execution of the program.
(We need not pass the source code to the user)
• The program needs to be translated once only. Then it can be executed again and again.
• Execution time is shorter (no translation is needed during run-time).
• Syntax errors (eg. typing mistakes) are checked already during compilation.
Less run-time mistakes will be made.
Programming process
• Developing the simplest programs require
the following steps:
• Start->Problem Identification->Task
Analysis-> Data analysis-> Deciding I/O->
developing algorithms->Coding->Testing->
Debugging-> Result
Therefore programmers have to:

• Absorb and use emerging technical


information
• Create sound software system architectures
• Understand and devise effective algorithms
• Be proficient with the syntax and style of
programming languages
• Diagnose and correct programming errors

1-24
The algorithm phase
• The algorithm phase is very important.
• What is an algorithm?
• A set of explicit, clear finite steps to obtain the
desired output in finite time.
• It is developed to produce the most efficient
approach to solve a problem.
• Efficient in terms of speed and memory usage.
• Coding is implementing an algorithm in the
programming language syntax.
• Pictorial representation
of an algorithm
• Depicts actual logic or
flow of the program
• See also pseudo code
Programming language
• Computer programs are written in programming languages.
• If a program contains even a very small error, the computer cannot understand
it.
• A programming language is an artificial language based on a set of grammar
rules.
• We use a programming language to convert an algorithm into a computer
program to enable the computer to solve the problem.
• There are hundreds of programming languages:
- some are general-purpose
- some are specific-purpose, such as business programs or scientific programs
(eg. APL)
• Very often, more than one programming language may be suitable for a task.
Programming language. contd.
• The goal of programming is to develop
programs that are clear(?), efficient(?) and
robust(?).
Generational development
First-generation language (1GL)
• Machine language: a string of 0s and 1s.
• Example, add EAX and EBX registers and store the result
back to EAX: 03 C3
• Instructions in machine languages are numbers stored as
bytes.
• Can be understood by a computer at once.
• But it is hard to read and understand by us. Difficult to
learn.
• Each type of computers understands its own machine
language only: machine-dependent.
• Therefore, the programs are not portable
Second-generation language (2GL)
• Assembly language.
• Stored as text.
• Example: to add EAX and EBX registers and store the result back
to EAX: add EAX, EBX
• Each assembly instruction represents exactly one machine
instruction.
• Assembler is needed to convert assembly language programs into
machine code so that they can be executed.
• Each type of computers understands its own assembly language
only.
ie. also machine-dependent.
• We may have to learn a new assembly language when we use
another type of computer.
3rd and 4th Generation (4GL)
• Also called Procedural language:
solves a problem by executing a sequence of steps
(ie. how). E.g Java, C, Pascal
• Fourth Generation Languages (4GL) have:
– Strong data structure support with persistence
– Support for application/problem-specific ideas
• SQL is a good example - Structured Query
language - a programming language for managing
databases ina platform/vendor independent way
32
..…3rd and 4th GL

• Also called declarative language:


specifies what needs to be done without going into the
details.
• Often used to access databases.
• Example: Structured Query Language (SQL)
SELECT * FROM RECORDS WHERE NAME =
"CHAN"
5th and 6th Generations
• 5GL are intended to allow non-specialists to
use Artificial Intelligence (AI) ideas - many
based on logical Inference
– Prolog is a classic example - it provides a logic
inference engine with a command line interface
and language syntax
• 6GLs are a bit less well defined - typically
based on neural network engines with an
appropriate syntax - mostly still experimental.
34
Program Structure
Reminder of some terminology.
In a natural language we usually think in terms of
lexical, syntactic and semantic levels.
• Lexical level - concerns the vocabulary (set) of
words
• Syntax says how the words are allowed to be
strung together to make sentences
• Semantics level addresses what it means
This does not quite work for programming
languages…
35
Syntactic Level
• The rules specify what “words” are allowed
to appear where
• eg reserved keywords; symbols and
identifiers in a typical programming
language
• Often these syntax rules are designed to be
close to natural language constructs
– eg if…then…else construct

36
Semantics
• What do language notions mean ?
• For example - “what will happen when the
value of an expression is calculated?”
• This is the semantics of the expression
• Semantics of each notion combine to define
the semantics of the whole language
• Semantics can be described formally - but
much harder than context-free grammars used
to describe syntax - well beyond our scope for
this paper.
159.331 Prog Lang & Alg 37
38

You might also like