Memory Data Register

advertisement
The Computer Processor
A closer look
When a program is run, program and data are copied from the hard drive
into Main Memory
Program
HARD DISK
MAIN MEMORY
A simple program that has been copied from the hard drive and put into
main memory
von-Neuman machine-Stored Program Approach. Where
both the data and program stored in main memory
MAIN MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
Fetch-Decode-Execute
Fetch: The next instruction is fetched from
Main Memory.
Decode: The instruction gets
interpreted/decoded, signals produced to
control other internal components (ALU for
example).
Execute: The instructions get executed
(carried out)
The processor contains a number of special
purpose registers.
A register is an extremely fast piece of onchip memory used for small temporary
storage.
Each of the special purpose registers have
an important role, when a series of program
instructions are fetched-decodedexecuted.
Special purpose registers
General purpose registers
Arithmetic
Logic Unit
Current
Instruction
Register
R0
R1
R2
Program
Counter
Status
Register
R3
R4
R5
Control
Unit
Memory
Address
Register
Memory
Data
Register
The Program Counter
The program counter holds the address of the next instruction
that is to be fetched-decoded-executed. This will increment
automatically as the current instruction is being decoded.
Arithmetic
Logic Unit
Current
Instruction
Register
R0
R1
R2
Program
Counter:
Status
Register
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
500
Control Unit
R3
MAIN
MEMORY
ADDRESS
R5
Memory
Address
Register
Memory
Data
Register
Memory Address Register (MAR)
The Memory Address Register (MAR) holds the address of the current
instruction being executed. It points to the relevant location in
memory where the required instruction is (at this stage the address is
simply copied from the Program Counter).
Arithmetic
Logic Unit
Current
Instruction
Register
R0
R1
R2
Program
Counter:
Status
Register
R3
MAIN
MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
500
R5
Control Unit
Memory
Address
Register:
500
Memory
Data
Register
MAR  [PC] (contents of Program
Counter copied to the Memory
Address Register)
Memory Data Register (MDR or MBR)
The Memory Data Register can contain both instructions and data. At this
stage, an instruction has been fetched and is being stored here en route to
the Current Instruction Register. The instruction is copied from the memory
location pointed to by the MAR.
Arithmetic
Logic Unit
Current
Instruction
Register
R0
R1
R2
Program
Counter:
R3
Status
Register
MAIN
MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
500
R5
Control Unit
Memory
Address
Register:
500
Memory
Data
Register:
LDA 1000
MBR  [Memory] addressed
(Contents of addressed memory is
copied to the memory buffer register)
Current Instruction Register (CIR)
The Current Instruction Register is used to store the current
instruction to be decoded and executed (copied from the MDR).
Arithmetic
Logic Unit
Current
Instruction
Register:
LDA 1000
R0
R1
R2
Program
Counter:
Status
Register
R3
MAIN
MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
500
R5
Control Unit
Memory
Address
Register:
500
Memory
Data
Register:
LDA 1000
CIR  [MBR]
(If contents of MBR is an instruction
then it is copied to the Current
Instruction Register)
Decoding and executing the instruction
The instruction in the CIR gets decoded. In this example, the instruction is telling
the processor to load the value in memory location 1000 (03) to the accumulator
(one of the general purpose registers are usually used for the accumulator). As this
happens the Program Counter automatically increments.
Arithmetic
Logic Unit
Current
Instruction
Register:
LDA 1000
R0
R1
R2
Program
Counter:
R3
Status
Register
MAIN
MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
503
R5
Control Unit
Memory
Address
Register:
500
Memory
Data
Register:
LDA 1000
PC  [PC] + 1
[CIR] decoded and executed
The Control Unit
The control unit co-ordinates all of these fetch-decodeexecute activities. At each clock pulse, it controls the movement
of data and instructions between the registers, main memory
and input and output devices.
Arithmetic
Logic Unit
Current
Instruction
Register:
LDA 1000
R0
R1
R2
Program
Counter:
Status
Register
R3
MAIN
MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
503
R5
Control
Unit
Memory
Address
Register:
1000
Memory
Data
Register:
03
Status Register
The Status Register stores a combination of bits used to indicate the result of an
instruction. For example one bit will be set to indicate that an instruction has caused an
overflow. Another bit will be set to indicate that the instruction produced a negative result.
The Status Register also indicates whether an interrupt has been received (we will look at
this later).
Arithmetic
Logic Unit
Current
Instruction
Register:
LDA 1000
R0
R1
R2
Program
Counter:
Status
Register
R3
MAIN
MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
503
R5
Control Unit
Memory
Address
Register:
1000
Memory
Data
Register:
03
Arithmetic Logic Unit
The Arithmetic Logic Unit carries out any arithmetic and logical operations (calculations
and value comparisons) required by any instruction that is executed. For example
instruction at 503 would require the Arithmetic Logical Unit to add the number in location
1001 to the value already in the accumulator.
Arithmetic
Logic Unit
Current
Instruction
Register:
LDA 1000
R0
R1
R2
Program
Counter:
Status
Register
R3
MAIN
MEMORY
ADDRESS
CONTENTS
500
LDA 1000
503
ADD 1001
506
STO 1002
…
….
1000
03
1001
04
1002
05
R4
503
R5
Control Unit
Memory
Address
Register:
1000
Memory
Data
Register:
03
Special Purpose Registers
Arithmetic
Logic Unit
Current
Instruction
Register:
LDA 1000
R0
R1
R2
Program
Counter:
Status
Register
R3
R4
503
R5
Control Unit
Memory
Address
Register:
1000
Memory
Data
Register:
03
So why use special
purpose registers
for all of this
passing of data and
instructions, rather
than using main
memory?
How much did you remember ?
Test time!
Download