Unit 1
Unit 1
EduTechLearners
(http://www.edutechlearners.com)
COMPUTER ORGANISATION
AND ARCHITECTURE
The components from which computers are built,
built
i.e., computer organization.
In contrast,
contrast computer architecture is the science
of integrating those components to achieve a
level of functionalityy and p
performance.
It is as if computer organization examines the
lumber, bricks, nails, and other building
g material
While computer architecture looks at the design
of the house.
http://www.edutechlearners.com 2
UNIT-1
UNIT 1 CONTENTS
• Evolution of Computer Systems (Historical
Prospective)
p )
• Computer Types
• Functional units
• Bus structures
• Register Transfer and Micro-operations
• Information Representation
• Instruction Format and Types
• Addressing modes
• Machine and Assembly Language Programming
• Macros and Subroutines
http://www.edutechlearners.com 3
HISTORICAL PROSPECTIVE
Brief History of Computer Evolution
Two phases:
1. b f
before VLSI 1945
194 – 1978
19 8
ENIAC
IAS
IBM
PDP-8
2. VLSI 1978 present day
microprocessors AND microcontrollers…
http://www.edutechlearners.com 4
Evolution of Computers
p
FIRST GENERATION (1945 – 1955)
Program and data reside in the same memory
(stored program concepts – John von Neumann)
ALP was made used to write programs
Vacuum tubes were used to implement the
functions (ALU & CU design)
Magnetic core and magnetic tape storage
devices are used
Using electronic vacuum tubes, as the switching
components
p
http://www.edutechlearners.com 5
SECOND GENERATION (1955 –
1965)
Transistor were used to design ALU & CU
HLL is used (FORTRAN)
To convert HLL to MLL compiler were used
Separate I/O processor were developed to
operate in parallel with CPU, thus improving the
performance
Invention of the transistor which was faster,
smaller and required considerably less power to
operate
http://www.edutechlearners.com 6
THIRD GENERATION (1965
(1965-1975)
1975)
IC technology improved
Improved IC technology helped in designing low
cost, high speed processor and memory
modules
d l
Multiprogramming, pipelining concepts were
incorporated
p
DOS allowed efficient and coordinate operation
of computer system with multiple users
C h and
Cache d virtual
i t l memory concepts t were
developed
More than one circuit on a single
g silicon chip
p
became available
http://www.edutechlearners.com 7
FOURTH GENERATION (1975-
1985)
CPU – Termed as microprocessor
INTEL, MOTOROLA, TEXAS,NATIONAL
semiconductors started developing
microprocessor
i
Workstations, microprocessor (PC) & Notebook
computers
p were developed
p
Interconnection of different computer for better
communication LAN,MAN,WAN
C
Computational
t ti l speed
d increased
i d by
b 1000 times
ti
Specialized processors like Digital Signal
Processor were also developedp
http://www.edutechlearners.com 8
BEYOND THE FOURTH GENERATION
(1985 – TILL DATE)
E-Commerce,
E Commerce E- E banking,
banking home office
ARM, AMD, INTEL, MOTOROLA
Hi h speed
High d processor - GHz
GH speed
d
Because of submicron IC technology lot of
added features in small size
http://www.edutechlearners.com 9
COMPUTER TYPES
Computational power
Type of application
http://www.edutechlearners.com 10
DESK TOP COMPUTER
http://www.edutechlearners.com 11
WORK STATIONS
• More computational power than PC
•Costlier
•Used to solve complex problems which arises in
engineering application (graphics, CAD/CAM etc)
http://www.edutechlearners.com 12
SERVER SYSTEM
SUPER COMPUTERS
http://www.edutechlearners.com 15
B i T
Basic Terminology
i l
Input
Whatever is put into a computer system
system.
Data
Refers to the symbols that represent facts, objects, or ideas.
Information
The results of the computer storing data as bits and bytes; the words,
numbers, sounds, and graphics.
Output
Consists of the processing results produced by a computer
computer.
Processing
Manipulation of the data in many ways.
Memory
y
Area of the computer that temporarily holds data waiting to be
processed, stored, or output.
Storage
Area of the computer that holds data on a permanent basis when it is not
immediately needed for processing.
http://www.edutechlearners.com 16
Basic Terminology
•Assembly y language
g g program
p g ) – Programs
(ALP)
( g are
written using mnemonics
•Assembler
A bl – is
i a software
ft which
hi h converts
t ALP tto MLL
(Machine Level Language)
http://www.edutechlearners.com 18
Functional Units
IMPORTANT
SLIDE !
F
Function
ti
ALL computer functions are:
Data PROCESSING
Data STORAGE Data = Information
Data MOVEMENT
CONTROL Coordinates How
Information is Used
NOTHING ELSE!
http://www.edutechlearners.com 20
F
Functional
ti l Units
U it
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
System Interconnections
• Eg: Keyboard
Keyboard, Mouse
Mouse, Joystick etc
http://www.edutechlearners.com 22
F
Functional
ti l Unit(I/O)
U it(I/O)
A computer handles two types of information :
Instruction :
An instruction controls the transfer of information between a
computer and its I/O devices and also within the computer.
A list of instructions that performs a task is called a
program, which is stored in the memory.
To execute a program, computer fetches the instructions
one by one and specifies the arithmetic and logical
operations to be performed which are needed for the
desired program.
A computer is completely controlled by the stored programs
except any external interrupts comes from any I/O device.
http://www.edutechlearners.com 23
F
Functional
ti l Unit(I/O)
U it(I/O)
Data :
Data is a kind of information which is used as an operand
for a program.
S data
So, d t can be b any numberb or character.
h t
Even, a list of instructions, means an entire program can be
data if it is processed by another high-level program.
In such case, that data is called source program.
The most well-known input device is the keyboard,
beside
bes de this,
s, there
eea are
e many
a yo other
e kinds
ds o
of input
pu
devices are available, i.e., mouses, joysticks etc.
http://www.edutechlearners.com 24
OUTPUT UNIT
• Converts the binary format data to a
format that a common man can
understand
• Displays the processed results.
• Eg: Monitor, Printer, LCD, LED etc
http://www.edutechlearners.com 25
MEMORY UNIT
Composed of large array of bytes
bytes.
Store programs and data .
Parts of the memory subsystem
Fetch/store controller
Fetch: Retrieve a value from memory
Store: Store a value into memory
Memory address register (MAR)
Memory data register (MDR)
Memory cells withhttp://www.edutechlearners.com
decoder(s) to select individual 26
cells
T
Types off Memory
M Unit
U it
Primary storage
Fast and Direct Access
Programs must be stored in memory while they
are being executed.
Large number of semiconductor storage cells.
RAM and d ROM
Secondary storage
used for bulk storage or mass storage
storage.
Indirect Access and slow.
Magnetic Harddisks
Harddisks,CDs.
CDs Etc
Etc.
http://www.edutechlearners.com 27
CACHE MEMORY
Memory access is much slower than processing
time.
Faster
F t memory isi too
t expensive
i tot use for
f allll
memory cells.
Small size, fast memory just for values currently
in use speeds computing time.
System Performance improved using this buffer
memory.
http://www.edutechlearners.com 28
Arithmetic and Logic Unit
(ALU)
Most computer operations are executed in
ALU of the processor.
L d th
Load the operands
d iinto
t memory – bring
b i ththem
to the processor – perform operation in ALU
– store the result back to memory or retain in
the processor.
Registers
Fast control of ALU
http://www.edutechlearners.com 29
Arithmetic and Logic Unit
(ALU)
Actual computations are performed
Primitive operation circuits
Arithmetic (ADD)
Comparison (CE)
Logic (AND)
Data inputs and results stored in registers
Multiplexor
p selects desired output
p
http://www.edutechlearners.com 30
Arithmetic and Logic Unit
(
(continued)
ti d)
ALU process
Values for operations copied into ALU’s
ALU s input
register locations
All circuits compute results for those inputs
Multiplexor selects the one desired result from all
values
Result value copied to desired result register
http://www.edutechlearners.com 31
Using a Multiplexor Circuit to Select the Proper ALU Result
http://www.edutechlearners.com 32
Th Control
The C t l Unit
U it
Manages stored program execution.
The timing signals that govern the I/O transfers are also
generated by
g y the control unit.
Task
http://www.edutechlearners.com 34
Overall operation of a
computer
t
4
4. Processed information is passed from output
unit .
5. All these activities described above are
sequentially done under the control signal from
the control unit.
http://www.edutechlearners.com 35
COMPUTER ARCHITECTURE:Bus
Structures
http://www.edutechlearners.com 36
BUS STRUCTURE
g CPU and memory
Connecting y
The CPU and memory are normally connected by three
groups of connections, each called a bus: data bus, address
bus and control bus
http://www.edutechlearners.com 38
REGISTER TRANSFER AND
MICROOPERATIONS
• Register Transfer Language
• Register Transfer
• Arithmetic Micro-operations
• Logic Micro-operations
• Shift Micro-operations
Mi ti
http://www.edutechlearners.com 39
SIMPLE DIGITAL SYSTEMS
http://www.edutechlearners.com 40
MICROOPERATIONS (1)
The operations on the data in registers are called micro-
operations.
The functions built into registers are examples of micro-
operations
Shift
Load
Clear
Increment
http://www.edutechlearners.com 41
MICRO-OPERATION (2)
An elementary operation performed (during
one clock pulse), on the information stored
in one or more registers
Registers ALU
1 clock cycle
(R) (f)
R f(R, R)
- Microoperations set
http://www.edutechlearners.com 43
REGISTER TRANSFER LEVEL
http://www.edutechlearners.com 44
REGISTER TRANSFER LANGUAGE
http://www.edutechlearners.com 45
DESIGNATION OF REGISTERS
Registers
g and their contents can be viewed and represented
p in
various ways
A register can be viewed as a single entity:
MAR
Registers may also be represented showing the bits of data they contain
http://www.edutechlearners.com 46
DESIGNATION OF REGISTERS
• Designation of a register
- a register
- portion of a register
- a bit of a register
http://www.edutechlearners.com 47
REGISTER TRANSFER
Copying the contents of one register to another is a register
transfer
A register transfer is indicated as
R2 R1
In this case the contents of register R1 are
copied (loaded) into register R2
A simultaneous transfer of all bits from the
source R1 to the destination register
R2,, during
g one clock pulse
p
Note that this is a non-destructive; i.e. the
contents of R1 are not altered by copying
(loading) them to R2
48
REGISTER TRANSFER
A register transfer such as
R3 R5
P: R2 R1
Load
T
Transfer
f occurs here
h
• The same clock controls the circuits that generate the control function
and the destination register
• Registers are assumed to use positive-edge-triggered flip-flops
http://www.edutechlearners.com 51
SIMULTANEOUS OPERATIONS
If two or more operations are to occur simultaneously,
they are separated with commas
P: R3 R5, MAR IR
http://www.edutechlearners.com 52
BASIC SYMBOLS FOR REGISTER
TRANSFERS
http://www.edutechlearners.com 53
CONNECTING REGISTERS
In a digital system with many registers, it is impractical to have
data and control lines to directly allow each register to be
loaded with the contents of every possible other registers
http://www.edutechlearners.com 54
BUS AND BUS TRANSFER
Bus is a path(of a group of wires) over which information is
transferred, from any of several sources to any of several destinations.
From a register to bus: BUS R
Register A Register B Register C Register D
Bus lines
Register
g A Register
g B Register
g C Register
g D
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
B1 C1 D 1 B2 C2 D 2 B3 C3 D 3 B4 C4 D 4
0 0 0 0
4 x1 4 x1 4 x1 4 x1
MUX MUX MUX MUX
x
select
y
4-line bus 55
TRANSFER FROM BUS TO A DESTINATION
Bus lines
REGISTER
Load
Reg. R0 Reg. R1 Reg. R2 Reg. R3
D 0 D1 D2 D 3
z E (enable)
Select 2x4
w
Decoder
S0 0
Select 1
S1 2
Enable 3 56
BUS TRANSFER IN RTL
R2 R1
or
http://www.edutechlearners.com 57
MEMORY (RAM)
Memory (RAM) can be thought as a sequential circuits
containing some number of registers
These registers
g hold the words of memory y
Each of the r registers is indicated by an address
These addresses range from 0 to r-1
Each register (word) can hold n bits of data
Assume the RAM contains r = 2k words. It needs the following
n data input lines
n data output lines data input lines
k address lines
n
A Read control line
A Write control line address lines
k
RAM
Read
unit
Write
n
R1 M[MAR]
This causes the following to occur
The contents
Th t t off the
th MAR gett sentt to
t the
th memory address
dd lines
li
A Read (= 1) gets sent to the memory unit
The contents of the specified address are put on the memory’s output data
lines
These get sent over the bus to be loaded into register R1
http://www.edutechlearners.com 60
MEMORY WRITE
To write a value from a register to a location in memory looks
like this in register transfer language:
M[MAR] R1
http://www.edutechlearners.com 61
SUMMARY OF R. TRANSFER MICROOPERATIONS
http://www.edutechlearners.com 62
MICROOPERATIONS
• Computer
p system
y microoperations
p are of four types:
yp
http://www.edutechlearners.com 63
ARITHMETIC MICROOPERATIONS
The basic arithmetic micro-operations are
Addition
Subtraction
Increment
Decrement
Binary Adder
FA C3 FA C2 FA C1 FA C0
C4 S3 S2 S1 S0
Binary Adder-Subtractor
B3 A3 B2 A2 B1 A1 B0 A0
FA C3 FA C2 FA C1 FA C0
C4 S3 S2 S1 S0
Binary
y Incrementer A3 A2 A1 A0 1
x y x y x y x y
HA HA HA HA
C S C S C S C S
C4 S3 S2 S1 S0 65
ARITHMETIC CIRCUIT
Cin
S1
S0
A0 X0 C0
S1 D0
B0
S0
0 Y0 FAC1
1
2
4x1
MUX
3
A1 X1 C1
S1 D1
B1
S0
Y1 FAC2
0
1
2
4x1
MUX
3
A2 X2 C2
S1 D2
Y2 FA
S0
B2 0 C3
1
2
4x1
MUX
3
A3 X3 C3
S1 D3
Y3 FA
S0
B3 0 C4
1
2 4 1
4x1
MUX
3 Cout
0 1
1
4X1 Fi
MUX
2
3 Select
S1
S0
Function table
S1 S0 Output -operation
0 0 F=AB AND
0 1 F = AB OR
1 0 F=AB XOR
1 1 F = A’ Complement
http://www.edutechlearners.com 69
APPLICATIONS OF LOGIC
MICROOPERATIONS
Logic micro-operations can be used to manipulate individual
bits or a portions of a word in a register
Consider the data in a register A. In another register, B, is bit
data that will be used to modify the contents of A
Selective set
Selective-set AA+B
Selective-complement AAB
Selective-clear
Selective clear AA•B B’
Mask (Delete) AA•B
Clear AAB
Insert A (A • B) + C
Compare
p AAB
…. http://www.edutechlearners.com 70
SELECTIVE SET
IIn a selective
l ti sett operation,
ti th
the bit pattern
tt in
i B is
i used
d tto sett
certain bits in A
1 1 0 0 At
1010 B
1 1 1 0 At+1 (A A + B)
http://www.edutechlearners.com 71
SELECTIVE COMPLEMENT
IIn a selective
l ti complement
l t operation,
ti th
the bit pattern
tt in
i B is
i used
d
to complement certain bits in A
1 1 0 0 At
1010 B
0 1 1 0 At+1 (A A B)
http://www.edutechlearners.com 72
SELECTIVE CLEAR
IIn a selective
l ti clearl operation,
ti th
the bit pattern
tt iin B iis used
d tto clear
l
certain bits in A
1 1 0 0 At
1010 B
0 1 0 0 At+1 (A A B
B’))
http://www.edutechlearners.com 73
MASK OPERATION
1 1 0 0 At
1010 B
1 0 0 0 At+1 (A A B)
http://www.edutechlearners.com 74
CLEAR OPERATION
IIn a clear
l operation,
ti if the
th bit
bits in
i the
th same position
iti ini A and
d B are
the same, they are cleared in A, otherwise they are set in A
1 1 0 0 At
1010 B
0 1 1 0 At+1 (A A B)
http://www.edutechlearners.com 75
INSERT OPERATION
An insert operation is used to introduce a specific bit pattern
into A register, leaving the other bit positions unchanged
This is done as
A mask operation to clear the desired bit positions, followed by
An OR operation to introduce the new bits into the desired positions
Example
p
Suppose you wanted to introduce 1010 into the low order four bits
of A: 1101 1000 1011 0001 A (Original)
1101 1000 1011 1010 A (Desired)
76
LOGICAL SHIFT
In a logical shift the serial input to the shift is a 0.
A right
g logical
g shift operation:
p
0
In a Register
g Transfer Language,
g g , the following
g notation is used
shl for a logical shift left
shr for a logical shift right
Examples:
R2 shr R2
R3 shl R3
http://www.edutechlearners.com 77
CIRCULAR SHIFT
IIn a circular
i l shift
hift th
the serial
i l iinputt iis th
the bit th
thatt is
i shifted
hift d outt off
the other end of the register.
http://www.edutechlearners.com 78
Logical versus Arithmetic Shift
CF
http://www.edutechlearners.com 79
ARITHMETIC SHIFT
• In a RTL, the following notation is used
– ashl for an arithmetic shift left
– ashr for an arithmetic shift right
– Examples:
» R2 ashr R2
» R3 ashl R3
http://www.edutechlearners.com 80
HARDWARE IMPLEMENTATION
OF SHIFT MICROOPERATIONS
Serial Select
input (IR) 0 for shift right (down)
1 for shift left (up)
S
MUX H0
0
1
A0
A1 S
MUX H1
0
A2 1
A3
S
MUX H2
0
1
S
MUX H3
0
1
Serial
input (IL)
http://www.edutechlearners.com 81
ARITHMETIC LOGIC SHIFT UNIT
S3
S2 Ci
S1
S0
Arithmetic Di
Circuit
Select
Ci+1
0 4x1 Fi
1 MUX
2
3
Ei
Logic
Bi
Ai
Circuit
Ai-1 shr
A i+1 shl
http://www.edutechlearners.com 83
Everything is in Binary !
(1’s and 0’s)
Computers
p are digital
g devices - theyy can onlyy
manipulate information in digital (binary) form.
Easy to represent 1 and 0 in electronic, magnetic and
optical devices
Only need two states
High/low
On/off
Up/down
etc
All information in a computer system is
Processed in binary form
Stored in binary form
Transmitted in binary form
http://www.edutechlearners.com 84
How is information converted
t Binary
to Bi form
f
I/O and Storage Devices are digital
I/O devices convert information to/from binary
A keyboard converts the character “A”A you type
into a binary code to represent “A”
E.g. “A” is represented by the binary code
01000001
Monitor converts 01000001 to the “A” that you
read
http://www.edutechlearners.com 85
Bits and Bytes
One binary digit i.e. 1 or 0 is called a bit
A group of 8 bits is one byte
Byte is the unit of storage measurement
http://www.edutechlearners.com 87
R
Representing
ti T Text-
t ASCII Code
C d
Each character is represented by a unique binary code.
ASCII iis one iinternational
t ti l standard
t d d th thatt specifies
ifi the
th
binary code for each character.
American Standard Code for Information Interchange g
It is a 7-bit code - every character is represented by 7 bits
There are other standards such as EBCDIC but these are
not widely used.
ASCII is being superceded by Unicode of which ASCII is
a subset.
subset Unicode is a 16 16-bit
bit code.
code
http://www.edutechlearners.com 88
Sample
p ASCII Codes
Char ASCII Decimal Char ASCII Decimal
9 011 1001 57
A 100 0001 65 a 110 0001 97
B 100 0010 66 b 110 0010 98
C 100 0011 67 c 110 0011 99
Y 101 1001 89 y 111 1001 121
http://www.edutechlearners.com 89
Comments on ASCII Codes
Codes for A to Z and a to z form collating sequences
A is 65, B is 66, C is 67 and so on
A is 97,
97 b is 98,
98 c is 99 and so on
Lowercase code is 32 greater than Uppercase equivalent
Note that digit ‘0’
0 is not the same as number 0
ASCII is used for characters
Not used to represent numbers (See later)
C d 0 to
Codes t 30 are typically
t i ll ffor Control
C t l Characters
Ch t
Bel - causes speaker to beep !
Carriage
g Return ((CR);
) LineFeed ((LF))
Others used to control communication between devices
SYN, ACK, NAK, DLE etc
http://www.edutechlearners.com 90
Review
All information stored/transmitted in binary
Devices convert to/from binary to other forms
that humans understand
Bits and Bytes
KB, Mb, GB, TB and PB are storage metrics
ASCII code is a 7-bit code to represent text
characters
h t
Text “numbers” not the same as “math's”
numbers
Do not add phone numbers or get average of PPS numbers
http://www.edutechlearners.com 91
Representing Numbers: Integers
http://www.edutechlearners.com 93
Representing Numbers: Decimal Numbers
http://www.edutechlearners.com 94
Representing Numbers: Binary Numbers
Binary numbers are Base 2 numbers
Only 2 digits: 0 and 1
Formally, the digits in a binary number are weighted by increasing powers
Formally
of 2
http://www.edutechlearners.com 95
Representing Numbers: Binary Numbers
http://www.edutechlearners.com 96
Representing Numbers: Binary Numbers
Exercises
http://www.edutechlearners.com 97
Representing Numbers: Converting Decimal to
Binary
To convert from one number base to another:
you repeatedly divide the number to be converted by the new base
the remainder of the division at each stage
g becomes a digit
g in the new base
until the result of the division is 0.
Example:
p To convert decimal 35 to binaryy we do the following:
g
Remainder
35 / 2 1
17 / 2 1
8/2 0
4/2 0
2/2 0
1/2 1
0
The result is read upwards giving 3510 = 1000112.
http://www.edutechlearners.com 98
Representing Numbers: Converting Decimal to
Binary
Exercise: Convert the following decimal numbers to binary
Shortcuts
To convert anyy decimal number which is a ppower of 2,, to binary, y,
simply write 1 followed by the number of zeros given by the power of 2.
For example,
5
32 is 2 , so we write it as 1 followed by 5 zeros, i.e. 10000;
128 is 27 so we write it as 1 followed by 7 zeros, zeros i.e.
i e 100 0000.
0000
Remember that the largest binary number that can be stored in a given number of bits
is
made up of n 11’ss.
An easy way to convert this to decimal, is to note that this is 2n - 1.
For example, if we are using 4-bit numbers, the largest value we can represent
is 1111 which is 24-1, i.e. 15
http://www.edutechlearners.com 99
Representing Numbers: Converting Decimal to
Binary
Binary Numbers that you should remember because they
occur so frequently
Binary Decimal
111 7
1111 15
http://www.edutechlearners.com 100
INSTRUCTION FORMAT
&
INSRUCTION TYPES
1
Instruction Formats
• Bits of the instruction are divided in to fields..
• Most common fields are:
OOPERATION ON CODE
CO FIELD tthatat specifies
spec es the t e
operation to be performed.
ADDRESS FIELD that designates g a memoryy
address or a processor register.
MODE FIELD that specifies the way the
operand or effective address is determined. Or we
can say it tells about addressing mode to be
adopted.
d d
http://www.edutechlearners.com 2
REGISTER ADDRESS
• Operands are generally stored in Memory or Processor
registers.
• Operands residing in memory are specified by their
memory address.
address
• Operands residing in processor registers are specified by
their register address.
• A register address is a binary number of k bits which
defines one of the 2^k registers in the CPU.
• For
F eg. CPU having
h i 16 processor registers
i R0 to R15 will
ill
have a address field of 4 bits.
• As binary no. 0101 will designate R5.
http://www.edutechlearners.com 3
Instruction Formats
• Most systems today are GPR systems.
• There are three types:
– Memory-memory where two or three operands may be in
memory.
memory
– Register-memory where at least one operand must be in a
register.
– Load-store where no operands may be in memory.
• The number of operands and the number of
available registers has a direct affect on instruction
length.
http://www.edutechlearners.com 4
Instruction Formats
• The next consideration for architecture design
concerns how
h th
the CPU will
ill store
t d
data
t .
• As the no. of address fields in the instruction format
depends on internal organization or architecture of its
registers.
• We have three choices of CPU organizations
1. A stack architecture
2. An accumulator architecture
3. A general purpose register architecture.
• In choosing one over the other, the tradeoffs are
simplicity (and cost) of hardware design with execution
speed and ease of use.http://www.edutechlearners.com 5
Instruction Formats
• In a stack architecture, instructions and operands
are implicitly taken from the stack.
– A stack cannot be accessed randomly.
• In an accumulator architecture,
architecture one operand of a
binary operation is implicitly in the accumulator.
– Both operand is in memory, creating lots of bus traffic.
• In a general purpose register (GPR)
architecture, registers can be used instead of
memory.
memory
– Faster than accumulator architecture.
– Efficient implementation for compilers.
– Results in longer instructions.
http://www.edutechlearners.com 6
STACK ARCHITECTURE
• Stack machines use one - and zero-operand
instructions.
• LOAD and STORE instructions require a single
memory address operand
operand.
• Other instructions use operands from the stack
implicitly.
• PUSH and POP operations involve only the stack’s
top element.
• Binary instructions (e
(e.g.,
g ADD,
ADD MULT) use the top
two items on the stack.
http://www.edutechlearners.com 7
STACK ARCHITECTURE
• Stack architectures require us to think about
arithmetic expressions a little differently.
• We are accustomed to writing expressions using
i fi notation,
infix t ti such
h as: Z = X + Y.
Y
• Stack arithmetic requires that we use postfix
notation:
t ti Z = XY+.
XY
• Eg. PUSH X
PUSH Y
ADD
http://www.edutechlearners.com 8
ACCUMULATOR ARCHITECTURE
http://www.edutechlearners.com 9
GENERAL REGISTER
ARCHITECTURE
• General processor registers and memory
word will be used here for storage of
operands.
operands
• It needs two to three address fields
• Eg:
E ADD R1, R1 R2,
R2 R3
ADD R1, R2
MOV R1, R2
ADD R1,
R1 X
http://www.edutechlearners.com 10
TYPES OF ADDRESS
INSTRUCTIONS
http://www.edutechlearners.com 11
Example to explain different address
instructions
• For example,
p , the infix expression,
p ,
Z = (X Y) + (W U)
Where X,Y,W and U are the
memory addresses where
the operands are stored.
http://www.edutechlearners.com 12
THREE ADDRESS INSTRUCTION
• With a three-address ISA, (e.g.,mainframes),
the infix expression,
Z = X Y + W U
might
i ht llook
k lik
like thi
this:
MUL R1,X,Y
MUL R2,W,U
ADD Z,R1,R2
http://www.edutechlearners.com 13
TWO ADDRESS INSTRUCTION
• In a two-address ISA, (e.g.,Intel, Motorola), the
infix expression,
Z = X Y + W U
might
i ht llook
k lik
like thi
this:
MOV R1,X
MUL R1,Y
MOV R2,W
MUL R2,U
ADD R1,R2
MOV Z,R1
http://www.edutechlearners.com 14
ONE ADDRESS INSTRUCTION
• In a one-address ISA, the infix expression,
Z = X Y + W U
looks like this:
LOAD X
MUL Y
STORE TEMP
LOAD W
MUL U
ADD TEMP
STORE Z
Accumulator will be used here.
http://www.edutechlearners.com 15
ZERO ADDRESS INSTRUCTION
• In a stack ISA, the postfix expression,
Z = X Y W U +
might look like this:
PUSH X
PUSH Y
U
MUL
PUSH W
Note: The result of
PUSH U
MUL a binary operation
ADD is implicitly stored
PUSH Z on the top of the
stack!
http://www.edutechlearners.com 16
RISC INSTRUCTION
• With a RISC (Reduced Instruction set computer)
the infix expression,
Z = X Y + W U
might
i ht llook
k lik
like thi
this:
LOAD R1,X
LOAD R2,Y
,
LOAD R3,W
LOAD R4,U
MUL R1
R1,R1,R2
R1 R2 Contains less no
no. of
MUL R3,R3,R4 instructions.
ADD R1,R1,R3
STORE ZZ,R1
R1
http://www.edutechlearners.com 17
Instruction Formats
• We have seen how instruction length is affected
by the number of operands supported by the ISA.
• In any instruction set, not all instructions require
th same number
the b off operands.d
• Operations that require no operands, such as
HALT, necessarily waste some space when fixed-
length instructions are used.
http://www.edutechlearners.com 18
Instruction types
yp
Instructions fall into several broad categories
that you should be familiar with:
• Data Transfer Instructions
• Data
D t MManipulation
i l ti IInstructions
t ti
Arithmetic
Logical
g
Shift
• Program Control Instructions
http://www.edutechlearners.com 19
Data Transfer Instructions
Name Mnemonic
Load LD
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
http://www.edutechlearners.com 20
Data Manipulation Instructions
Arithmetic Instructions:
Name Mnemonics
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with Carry ADDC
Subtract with borrow SUBB
Negate(2’ss compliment)
Negate(2 NEG
http://www.edutechlearners.com 21
Data Manipulation Instructions
Logical and Bit manipulation Instructions:
Name Mnemonics
Clear CLR
Compliment COM
AND AND
OR OR
EXOR XOR
Clear carryy CLRC
Set carry SETC
Compliment carry COMPC
Enable and Disable Interrupt EI & DI
http://www.edutechlearners.com 22
Data Manipulation Instructions
Shift Instructions:
Name Mnemonics
Logical shift Right SHR
Logical shift Left SHL
Arithmetic Shift Right SHRA
Arithmetic Shift Left SHLA
Rotate Right ROR
Rotate Left ROL
Rotate Right with carry RORC
Rotate Left with carry ROLC
http://www.edutechlearners.com 23
Program Control Instructions
Name Mnemonics
Branch BR
Jump JMP
Skip SKP
Call CALL
Return RET
Compare(by subtraction) CMP
Test(by
( y ANDing)
g) TST
http://www.edutechlearners.com 24
Program Control Instructions (Conditional
B
Branchh IInstructions)
t ti )
Instruction
Op-code Address A
Operand
• IInstruction
t ti includes
i l d the th A memory address
dd
• LDAC 5 – accesses memory location 5, reads the data (10)
aandd stores
sto es tthee data in tthee microprocessor’s
c op ocesso s accu
accumulator
u ato
• This mode is usually used to load variables and operands 28
into the CPU
Indirect mode
Op-code Address A
Instruction
Pointer to operand
http://www.edutechlearners.com 29
Register direct mode
Opcode Register Address R
Instruction Registers
Operand
Operand
R i
Registers Memory
• LDAC @R or LDAC (R) – the register contains the address
of the operand in the memory
• Register R (selected by the operand), contains value 5
which represents the address of the operand in the memory
(10)
31
• One fewer memory access than indirect addressing
Immediate mode
http://www.edutechlearners.com 32
Implicit
p addressing
g mode
• Doesn’t explicitly specify an operand
• The
Th instruction
i t ti implicitly
i li itl specifies
ifi th
the operand
dbbecause
always applies to a specific register
• This is not used for load instructions
• As an example, consider an instruction CLAC, that is
clearing the content of the accumulator in a processor and
it is always referring to the accumulator
• This mode is used also in CPUs that do use a stack to
store data;; theyy don’t specify
p y an operand
p because it is
implicit that the operand must come from the stack
http://www.edutechlearners.com 33
Displacement
p addressing
g mode
Opcode Register R Address A
Instruction
Pointer to
Operand
+ Operand
Registers
Memory
• Effective Address = A + (content of R)
• Address field hold two values
– A = bbase value
l
– R = register that holds displacement 34
– or vice versa
Relative addressing mode
• It is a particular case of the displacement addressing, where the
register
g is the pprogram
g counter;; the supplied
pp operand
p is an
offset; Effective Address = A + (PC)
• The offset is added to the content of the CPU’s program
counter register
g to g
generate the required
q address
• The program counter contains the address of next instruction to
be executed, so the same relative instruction will produce
different addresses at different locations in the program
• Consider that the relative instruction LDAC $5 is located at
memory address 10 and it takes two memory locations; the
next instruction is at location 12, so the operand is actually
l
located
t d att (12 +5)
5) 17
17; th
the iinstruction
t ti lloads
d ththe operand
d att
address 17 and stores it in the CPU’s accumulator
• This mode is useful for short jumps and reloadable code
http://www.edutechlearners.com 35
Indexed addressing
g mode
• Works like relative addressing g mode; instead
adding the A to the content of program counter
(PC), the A is added to the content of an index
register
• If the index register contains value 10, then the
instruction LDAC 5(X) reads data from memory
at location (5+10) 15 and stores it in the
accumulator
• Good for accessing arrays
– Effective Address = A + IndexReg
– R++
http://www.edutechlearners.com 36
Based addressing
g mode
http://www.edutechlearners.com 38
MACHINE AND
ASSEMBLY LANGAUGE
PROGRAMMING
http://www.edutechlearners.com 39
Computer Operations
• A computer
comp ter is a programmable electronic
device that can store, retrieve, and process
data
• Data and instructions to manipulate the data
are logically the same and can be stored in
the same place
• Store,, retrieve,, and p
process are actions that
the computer can perform on data
http://www.edutechlearners.com 40
Machine Language
http://www.edutechlearners.com 41
Machine Language
http://www.edutechlearners.com 42
Assembly Language
44
Assembly Process
http://www.edutechlearners.com 45