Download CPU Fetch-Execute Cycle and Computer Architecture and more Slides Information Systems in PDF only on Docsity!
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Chapter 2 Notes
Ch2: Computer Hardware
Computer Organization
- (^) The structure of the components in the computer
- (^) The function of those components
- (^) How the CPU works
- (^) The role of memory
- (^) The role of I/O devices
- (^) How to assemble a computer
The Structure of the Computer
The System Bus
The Bus continued
- (^) Data bus:
- (^) Used to send data and program instructions
- (^) from memory to the CPU
- (^) from the CPU to memory
- (^) between I/O device and the CPU
- (^) between I/O device and memory
- (^) Size of data bus is often size of computer’s word
Memory Read
Fetch-Execute Cycle
- (^) To execute a program, the CPU performs the fetch-
execute cycle
- (^) Fetch next instruction from memory
- (^) Decode the instruction
- (^) Execute the instruction
- (^) Store the result
Example: A Program
- (^) We use the following C program to better understand the
fetch-execute cycle
#include <stdio.h> // input/output library
void main( ) // start of the program
int a, b, c; // use 3 integer variables
scanf(“%d”, &a); // input a
scanf(“%d”, &b); // input b
if(a < b) // compare a to b, if a is less then b
c=a + b; // then set c to be their sum
else c=a-b; // otherwise set c to be their difference
printf(“%d”, c); // output the result, c
Program in Machine Language
- (^) Assembly language version of our C program is stored in
the computer in machine language
- (^) The first four instructions might look like this:
1000100 0000000000000000000100001 – input (from keyboard)
1000111 0010011000100101101010001 – store the datum in a
1000100 0000000000000000000100001 – input (from keyboard)
1000111 0010011000100101101010010 – store the datum in b
op code operand (datum)
Fetch-Execute Cycle
Registers Continued
- (^) IR – instruction register
- (^) Current instruction
- (^) Used during decoding
- (^) Status flags
- (^) To store information about the result of the previous ALU operation
- (^) positive, negative, zero
- (^) even or odd parity
- (^) carry
- (^) overflow
- (^) interrupt
Fetch-Execute Cycle: Details
- (^) Fetch:
- (^) PC stores address of next instruction
- (^) Fetch instruction at PC location
- (^) Increment PC
- (^) Instruction sent over data bus
- (^) Store instruction in IR
- (^) Decode:
- (^) Decode opcode portion in IR
- (^) Determine operand(s) from instruction in IR Input 33 Store a Input 33 Store b Load a Subt b Jge else Load a Add b Store c Jump next else: Load a Subt b Store c next: Load c Output 2049 Halt
Fetch-Execute Cycle: Example
- (^) Assume our program starts at location 5,000,
- (^) PC: 5,000,
- (^) IR: -------
- (^) Fetch instruction
- (^) PC: 5,000,
- (^) IR: 1000100 0000000000000000000100001
- (^) Increment PC to 5,000,
- (^) Decode instruction
- (^) Input operation (obtain input from keyboard)
- (^) Execute:
- (^) Take input value from keyboard
- (^) Move to AC
Continued
- (^) Fetch instruction
- (^) PC: 5,000,
- (^) IR: 1000111 0010011000100101101010001
- (^) Increment PC to 5,000,
- (^) Decode instruction
- (^) Store datum to memory location 0010011000100101101010001
(memory location storing variable a)