ICS 2102 Lecture 1 Hardware and Software Basics
ICS 2102 Lecture 1 Hardware and Software Basics
Computer Programming
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:
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
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.
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
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