Professional Documents
Culture Documents
MEMORY
PC R0
. ALU
R1
.
.
IR
.
R(n-1)
PROCESSOR
PROCESSOR
INPUT OUTPUT MEMORY PROCESSOR
Memory Locations and Addresses
Memory consists of many millions of
storage elements
One storage element can store one bit of
information
Memory is organized so that a group of n
bits (referred as word ) can be stored or
retrieved
n bits
.
.
.
.
.
.
b31 b30 … b1 b0
2^k - 1
Byte Addressability
a byte is 8 bits
the word length typically ranges from 16 to
64 bits
successive addresses refer to successive
byte locations in the memory (generally
used in computers)
Byte locations have addresses 0,1,2,.....
If the word length is 32 bits, successive
words are located at addresses 0,4,8,......
with each word consisting of four bytes.
Word
Address Byte Address Byte Address
0 0 1 2 3 0 3 2 1 0
4 4 5 6 7 4 7 6 5 4
. .
. .
. .
R1 ← [LOC]
The contents of memory location LOC are transferred
into processor register R1
R3 ← [R1] + [R2]
PLACE ← [R2]
Assembly Language Notation
Move LOC, R1
Add R1,R2,R3
Add A,B
Move B, C
in RTN
B ← [A]+[B]
C ← [B]
general instruction of this type has the format
Operation Source, Destination
Basic Instruction Types
Some machine instructions specify only one
operand.
When the second operand is needed, it is
understood implicitly to be in a unique
location, generally accumulator (a
processor register) is used
they become one address instructions
Add LOC
Load PLACE
Store PLACE
Basic Instruction Types
C= A+B
↓
Load A
Add B
Store C
Basic Instruction Types
Use of processor registers allows faster
accessing and results in shorter instructions
Load A, Ri or Move A, Ri
Store Ri, LOC or Move Ri,LOC
and
Add LOC, Ri
Basic Instruction Types
C= A+B
Assumptions we make
◦ Compiler allows one memory operand per instruction
.
.
.
Data for the
B program
.
.
.
C
Execution of the program
To begin execution of the program, the address
of its first instruction (i in this case) is placed into
the PC.
Processor fetches and executes the first
instruction using the information available in PC.
B Operand A B
.
.
.
R1 B Register B Operand
Address Contents
Move N,R1
Add #4,R2
Decrement R1
Data in memory
Branch>0 LOOP
SUM
Move R0,SUM
N n
NUM1
NUM2
.
.
.
NUMn
◦ The register or the memory location that
contains the address of operand is called
pointer
◦ Indirect Addressing through registers are
used extensively.
◦ But Indirect Addressing through memory
location is seldom used, because it
involves accessing memory twice to get
an operand
Index Addressing
◦ It is useful in dealing with lists and arrays
◦ The Effective Address of the operand is
generated by adding a constant value to the
contents of register
For example,
Add X(Ri), Rj
The EA of first operand is [Ri]+X
Add 20(R1),R2
.
.
.
1000 1000 R1
.
.
20=Offset
.
1020 Operand
INDEXED
(a) Offset is given as a constant
Add 1000(R1),R2
ADDRESSING
.
.
.
1000 20 R1
.
.
20=Offset
.
1020 Operand
N n
LIST Student ID
LIST + 4 Test 1
Student 1
LIST + 8 Test 2
LIST + 12 Test3
LIST + 16 Student ID
Test 1
Student 2
Test 2
Test3
.
.
.
INDEXED ADDRESSING USED IN ACCESSING TEST SCORES
IN THE LIST IN THE PREVIOUS FIGURE
Move #LIST,R0
Clear R1
Clear R2
Clear R3
Move N,R4
Move N,R1
Decrement R1
Data in memory
Branch>0 LOOP
SUM
Move R0,SUM
N n
NUM1
NUM2
.
.
.
NUMn
Auto decrement Addressing
◦ The contents of a register specified in the
instruction are first automatically decremented
and are then used as the effective address of the
operand
For Example,
Add -(R1), R0