CSE 243: Introduction To Computer Architecture and Hardware/Software Interface
CSE 243: Introduction To Computer Architecture and Hardware/Software Interface
CSE 243: Introduction To Computer Architecture and Hardware/Software Interface
Execution of an instruction
Recall the steps involved in the execution of an instruction by a processor:
Fetch an instruction from the memory. Fetch the operands. Execute the instruction. Store the results.
Several issues:
Where is the address of the memory location from which the present instruction is to be fetched? Where is the present instruction stored while it is executed? Where and what is the address of the memory location from which the data is fetched? ......
Basic processor architecture has several registers to assist in the execution of the instructions.
1
MAR
MDR Control
PC
R0 R1
IR
R(n-1)
-
Processor
Data Path
Processor Control path is responsible for: Instruction fetch and execution sequencing Operand fetch Saving results Data path: Contains general purpose registers Contains ALU Executes instructions
3
Memory
Fetch/Execute cycle
Execution of an instruction takes place in two phases:
Instruction fetch. Instruction execute.
Instruction fetch:
Fetch the instruction from the memory location whose address is in the Program Counter (PC). Place the instruction in the Instruction Register (IR).
Instruction execute:
Instruction in the IR is examined (decoded) to determine which operation is to be performed. Fetch the operands from the memory or registers. Execute the operation. Store the results in the destination location.
Memory organization
Recall:
Information is stored in the memory as a collection of bits. Collection of bits are stored or retrieved simultaneously is called a word. Number of bits in a word is called word length. Word length can be 16 to 64 bits.
Bytes are grouped into words, word length can also be expressed as a number of bytes instead of the number of bits:
Word length of 16 bits, is equivalent to word length of 2 bytes. Words may be 2 bytes (older architectures), 4 bytes (current architectures), or 8+ bytes (modern architectures).
Memory is viewed as a sequence of bytes. Address of the first byte is 0 k Address of the last byte is 2 - 1, where k is the number of bits used to hold memory address E.g. when k = 16, Address of the first byte is 0 Address of the last byte is 65535 E.g. when k = 2, Address of the first byte is ? Address of the last byte is ?
Byte 2 -1 8
Word #1
Consider a memory organization: 16-bit memory addresses Size of the memory is ? Word length is 4 bytes Number of words = Memory size(bytes) = ? Word length(bytes) Word #0 starts at Byte #0. Word #1 starts at Byte #4. Last word (Word #?) starts at Byte#?
Word #?
Word #0
Byte 3 Byte 4
Word #1
MDR
Addr 65532
Word #16383 MDR contains either the data to be written to that address or read from that address.
10
Memory operations
Memory read or load:
Place address of the memory location to be read from into MAR. Issue a Memory_read command to the memory. Data read from the memory is placed into MDR automatically (by control logic).
11
Instruction types
Computer instructions must be capable of performing 4 types of operations. Data transfer/movement between memory and processor registers.
E.g., memory read, memory write E.g., addition, subtraction, comparison between two numbers. Branch instructions
12
13
Specifying the operands on which the instruction is to operate involves specifying the addresses of the operands.
14
An operand is called a destination operand if: It appears on the left-hand side of an expression. E.g., Add A, B, C (C = A + B)
C is a destination operand.
15
16
Instruction types
Instructions can also be classified based on the number of operand addresses they include.
3, 2, 1, 0 operand addresses.
3-address instructions are almost always instructions that implement binary operations. E.g. Add A, B, C (C = A + B)
k bits are used to specify the address of a memory location, then 3-address instructions need 3*k bits to specify the operand addresses. 3-address instructions, where operand addresses are memory locations are too big to fit in one word.
17
2-address instructions, where at least one operand is a processor register: E.g. Add A, R1 (R1 = A + R1) 1-address instructions require only one operand. E.g. Clear A (A = 0) 0-address instructions do not operate on operands. E.g. Halt (Halt the computer) How are addresses of operands specified in the instructions?
18
Addressing modes
Different ways in which the address of an operand in specified in an instruction is referred to as addressing modes. Register mode
Operand is the contents of a processor register. Address of the register is given in the instruction.
E.g. Clear R1
Absolute mode
Operand is in a memory location. Address of the memory location is given explicitly in the instruction.
E.g. Clear A
Also called as Direct mode in some assembly languages Register and absolute modes can be used to represent variables
19
Register, Absolute and Immediate modes contained either the address of the operand or the operand itself. Some instructions provide information from which the memory address of the operand can be determined
That is, they provide the Effective Address of the operand. They do not provide the operand or the address of the operand explicitly.
20
Operand
R1
Register
Operand
Operand is at address 1020 Register R1 contains 1000 Offset 20 is added to the contents of R1 to generate the address 20 Contents of R1 do not change in the process of generating the address R1 is called as an index register What address would be generated by Add 1000(R1), R0 if R1 had 20?
R1
1000
23
Autodecrement mode
Effective address of the operand is the contents of a register specified in the instruction. After accessing the operand, the contents of this register are automatically incremented to point to the next consecutive memory location. (R1)+ Effective address of the operand is the contents of a register specified in the instruction. Before accessing the operand, the contents of this register are automatically decremented to point to the previous consecutive memory location. -(R1)
Autoincrement and Autodecrement modes are useful for implementing Last-In-First-Out data structures.
24
Recall that the information is stored and retrieved one word at a time.
In most computers, increment and decrement amounts are equal to the word size in bytes.
25