What
is the most intelligent computer ?
1
Answer ...
2
How does an Electronic Computer
Differ from our Brain ?
Feature Computer Our Brilliant Brain
Intelligence Dumb Intelligent
Speed of basic calculations Ultra-fast Slow
Can get tired Never After sometime
Can get bored Never Almost always
* Computers are ultra-fast and ultra-dumb
3
How to Instruct a Computer ?
compile execute
Program Executable Output
* Write a program in a high level language – C,
C++, Java
* Compile it into a format that the computer
understands
* Execute the program
4
What Can a Computer Understand ?
* Computer can clearly NOT understand
instructions of the form
* Multiply two matrices
* Compute the determinant of a matrix
* Find the shortest path between Mumbai and Delhi
* They understand :
* Add a + b to get c
* Multiply a * b to get c
5
The Language of Instructions
* Humans can understand
* Complicated sentences
* English, French, Spanish
* Computers can understand
* Very simple instructions
The semantics of all the instructions supported by a processor is known
as its instruction set architecture (ISA). This includes the semantics of
the instructions themselves, along with their operands, and interfaces
with peripheral devices.
6
Features of an ISA
* Example of instructions in an ISA
* Arithmetic instructions : add, sub, mul, div
* Logical instructions : and, or, not
* Data transfer/movement instructions
* Complete
* It should be able to implement all the programs
that users may write
7
Features of an ISA
* Concise
* The instruction set should have a limited size.
Typically an ISA contains 32-1000 instructions.
* Generic
* Instructions should not be too specialized, e.g.
add14 (adds a number with 14) instruction is too
specialized
* Simple
* Should not be very complicated.
8
Designing an ISA
* Important questions that need to be answered :
* How many instructions should we have ?
* What should they do ?
* How complicated should they be ?
Two different paradigms : RISC and CISC
RISC CISC
(Reduced Instruction Set (Complex Instruction
Computer) Set Computer)
9
RISC vs CISC
A reduced instruction set computer (RISC) implements
simple instructions that have a simple and regular
structure. The number of instructions is typically a small
number (64 to 128). Examples: ARM, IBM PowerPC,
HP PA-RISC
A complex instruction set computer (CISC) implements
complex instructions that are highly irregular, take
multiple operands, and implement complex
functionalities. Secondly, the number of instructions is
large (typically
500+). Examples: Intel x86, VAX
10
Takeaway Points..
* Computers are dumb yet ultra-fast machines.
* Instructions are basic rudimentary commands used to
communicate with the processor. A computer can execute
billions of instructions per second.
* The compiler transforms a user program written in a high level
language such as C to a program consisting of basic machine
instructions.
* The instruction set architecture(ISA) refers to the semantics of
all the instructions supported by a processor.
* The instruction set needs to be complete. It is desirable if it is
also concise, generic, and simple.
11
Completeness of an ISA
How can we ensure that an
ISA is complete ?
* Complete means :
* Can implement all types of programs
* For example, if we just have add instructions, we
cannot subtract (NOT Complete)
12
Completeness of an ISA – II
How to ensure that we have just enough
instructions such that we can implement
every possible program that we might
want to write ?
13
Answer
* Let us look at results in theoretical computer science
* Is there an universal ISA ?
Universal ISA Universal Machine
The universal machine has a set of basic actions, and each such
action can be interpreted as an instruction.
14
The Turing Machine – Alan Turing
* Facts about Alan Turing
* Known as the father of computer science
* Discovered the Turing machine that is the most
powerful computing device known to man
* Indian connection : His father worked with the Indian Civil
Service at the time he was born. He was posted in
Chhatrapur, Odisha.
15
Turing Machine
Infinite Tape
L R
State Register Tape Head
The tape head
can only move
left or right
Action Table
(old state, old symbol) -> (new state, new symbol, left/right)
16
Operation of a Turing Machine
* There is an inifinite tape that extends to the left and right. It
consists of an infinite number of cells.
* The tape head points to a cell, and can either move 1 cell to the left
or right
* Based on the symbol in the cell, and its current state, the Turing
machine computes the transition :
* Computes the next state
* Overwrites the symbol in the cell (or keeps it the same)
* Moves to the left or right by 1 cell
* The action table records the rules for the transitions.
17
Example of a Turing
Machine
Design a Turing machine to increment a number by 1.
$ 7 3 4 6 9 $
Tape Head
* Start from the rightmost position. (state = 1)
* If (state = 1), replace a number x, by x+1 mod 10
* The new state is equal to the value of the carry
* Keep going left till the '$' sign
18
More about the Turing Machine
* This machine is extremely simple, and extremely
powerful
* We can solve all kinds of problems – mathematical problems,
engineering analyses, protein folding, computer games, …
* Try to use the Turing machine to solve many more types of
problems (TODO)
19
Church-Turing Thesis
Church-Turing thesis: Any real-world computation can be translated
into an equivalent computation involving a Turing machine.
(source: Wolfram Mathworld)
* Note : It is a thesis, not a theorem
* For the last 60 years, nobody has found a counter-example
Definition:
Any computing system that is equivalent to a Turing machine is said to be
Turing complete.
20
Universal Turing Machine
* For every problem in the world, we can design a Turing Machine
(Church-Turing thesis)
* Can we design a universal Turing machine that can simulate any
Turing machine. This will make it a universal machine (UTM)
* Why not? The logic of a Turing machine is really simple. We
need to move the tape head left, or right, and update the
symbol and state based on the action table. A UTM can easily do
this.
* A UTM needs to have an action table, state register, and tape
that can simulate any arbitrary Turing machine.
21
Universal Turing Machine
Prog. 1 Prog. 2 Prog. 3
Turing Machine 1 Turing Machine 2 Turing Machine 3
Universal Turing Machine
22
A Universal Turing Machine
Simulated State Register
Simulated Action Table Work Area
L R
Generic State Register Tape Head
Generic Action Table
23
A Universal Turing Machine
Program
Counter
Simulated State(PC)
Register
Instruction
Simulated Action Table Work Area
Memory Data Memory
L R
Generic State Register Tape Head
Program
PC CPU
Generic Action Table
Computer Inspired from the Turing
Machine
Program
CPU
Program Control Arithmetic
Counter (PC) Unit Unit
Instruction
Program Data
Memory
25
Elements of a Computer
* Memory (array of bytes) contains
* The program, which is a sequence of instructions
* The program data → variables, and constants
* The program counter(PC) points to an instruction in a program
* After executing an instruction, it points to the next instruction
by default
* A branch instruction makes the PC point to another instruction
(not in sequence)
* CPU (Central Processing Unit) contains the
* Program counter, instruction execution units
26
Let us now design an
ISA ...
* Single Instruction ISA
* sbn – subtract and branch if negative
* Add (a + b) (assume temp = 0)
1: sbn temp, b, 2
2: sbn a, temp, exit
27
Single Instruction ISA - II
* Add the numbers – 1 … 10
Initialization:
one = 1
index = 10
sum = 0
1: sbn temp, temp, 2 // temp = 0
2: sbn temp, index, 3 // temp = -1 * index
3: sbn sum, temp, 4 // sum += index
4: sbn index, one, exit // index -= 1
5: sbn temp, temp, 6 // temp = 0
6: sbn temp, one, 1 // (0 - 1 < 0), hence goto 1
exit
28
Multiple Instruction ISA
* Arithmetic Instructions
* add, subtract, multiply, divide
* Logical Instructions
* or, and, not
* Move instructions
* Transfer values between memory locations
* Branch instructions
* Move to a new program location, based on the values of some
memory locations
29
Designing Practical Machines
CPU
ALU
Instruction
Data
memory Control memory
I/O devices
Harvard Architecture
30
Von-Neumann Architecture
CPU
ALU
Memory Control I/O devices
31
Problems with Harvard/ Von-Neumann
Architectures
* The memory is assumed to be one large array of
bytes
* It is very very slow
General Rule: Larger is a structure, slower it is
* Solution:
* Have a small array of named locations (registers) that can
be used by instructions
* This small array is very fast
Insight: Accesses exhibit locality (tend to use the same
variables frequently in the same window of time)
32
Uses of Registers
* A CPU (Processor) contains set of registers (16-64)
* These are named storage locations.
* Typically values are loaded from memory to registers.
* Arithmetic/logical instructions use registers as input
operands
* Finally, data is stored back into their memory locations.
33
Example of a Program in Machine
Language with Registers
1: r1 = mem[b] // load b
2: r2 = mem[c] // load c
3: r3 = r1 + r2 // add b and c
4: mem[a] = r3 // save the result
* r1, r2, and r3, are registers
* mem → array of bytes representing memory
34
Machine with Registers
CPU
Registers
ALU
Memory Control I/O devices
35
Where are we ...
* We have derived the structure of a computer from
theoretical fundamentals.
* It has a CPU with a program counter & registers,
memory, and peripherals.
* The Instruction Set Architecture (ISA) is the link
between hardware and software.
Instruction
Set
Architecture
36
Instruction Set
Architecture
* Interface between software and hardware
* A compiler converts a program into machine instructions in the
given ISA
* The processor executes the instructions in the ISA
* We shall first look at the software aspect of the ISA
(assembly programs)
* Then look at implementing the ISA by designing the
processor
* Then, we shall make the computer more efficient by
designing fast memory/ storage systems
37
THE END
38