2-Instruction Processing and Examples of Instruction-02!08!2023
2-Instruction Processing and Examples of Instruction-02!08!2023
Model
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
INPUT OUTPUT
Ke yb o a rd M o n it o r
Mous e PROCES S ING UNIT P rin t e r
Sca nne r LED
Dis k ALU TEMP Dis k
Memory
k x m array of stored bits (k is usually 2n)
Address
• unique (n-bit) identifier of location 0000
0001
Contents 0010
0011 00101101
• m-bit value stored in location 0100
0101
0110
•
Basic Operations: •
•
1101 10100010
LOAD 1110
• read a value from a memory location 1111
STORE
• write a value to a memory location
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Interface to Memory
How does processing unit get data to/from memory?
MAR: Memory Address Register
M EM OR Y
MDR: Memory Data Register
MAR MDR
To read a location (A):
1. Write the address (A) into the MAR.
2. Send a “read” signal to the memory.
3. Read the data from MDR.
To write a value (X) to a location (A):
1. Write the data (X) to the MDR.
2. Write the address (A) into the MAR.
3. Send a “write” signal to the memory.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Processing Unit
Functional Units
• ALU = Arithmetic and Logic Unit
• could have many functional units.
some of them special-purpose PROCES S ING UN IT
(multiply, square root, …)
• LC-2 performs ADD, AND, NOT ALU TEMP
Registers
• Small, temporary storage
• Operands and results of functional units
• LC-2 has eight register (R0, …, R7)
Word Size
• number of bits normally processed by ALU in one instruction
• also width of registers
• LC-2 is 16 bits
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Control Unit
Orchestrates execution of the program
CONTR OL UNIT
PC IR
Instruction Processing
Decode instruction
Evaluate address
Execute operation
Store result
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Instruction
The instruction is the fundamental unit of work.
Specifies two things:
• opcode: operation to be performed
• operands: data/locations to be used for operation
S
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
S
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Examples: D
• add offset to base register (as in LDR)
• add offset to PC (or to part of PC) EA
• add offset to zero
OP
EX
S
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Examples: D
• load data from memory (LDR)
• read data from register file (ADD) EA
OP
EX
S
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Examples: D
• send operands to ALU and assert ADD signal
• do nothing (e.g., for loads and stores) EA
OP
EX
S
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Examples: D
• result of ADD is placed in destination register
• result of memory load is placed in destination register EA
• for store instruction, data is stored to memory
write address to MAR, data to MDR OP
assert WRITE signal to memory
EX
S
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
“1”
“0”
Machine time
Cycle
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.