Monday 17 September 2012

CPU design (part 2)


            Register Organization
There are a variety of CPU registers that are employed to control the operation of the CPU. Most of these, on most machines, are not visible to the user.
Different machines will have different register organizations and use different terminology. We will discuss here the most commonly used registers which are part of most of the machines.
Four registers are essential to instruction execution:
Program Counter (PC): Contains the address of an instruction to be fetched. Typically, the PC is updated by the CPU after each instruction fetched so that it always points to the next instruction to be executed. A branch or skip instruction will also modify the contents of the PC.
Instruction Register (IR): Contains the instruction most recently fetched. The fetched instruction is loaded into an IR, where the opcode and operand specifiers are analyzed.
Memory Address Register (MAR): Containts the address of a location of main memory from where information has to be fetched or information has to be stored. Contents of MAR is directly connected to the address bus.
Memory Buffer Register (MBR): Contains a word of data to be written to memory or the word most recently read. Contents of MBR is directly connected to the data bus.It is also known as Memory Data Register(MDR).
Apart from these specific register, we may have some temporary registers which are not visible to the user. As such, there may be temporary buffering registers at the boundary to the ALU; these registers serve as input and output registers for the ALU and exchange data with the MBR and user visible registers.
Processor Status Word
All CPU designs include a register or set of registers, often known as the processor status word (PSW), that contains status information. The PSW typically contains condition codes plus other status information. Common fields or flags include the following:
  • Sign: Contains the sign bit of the result of the last arithmatic operation.
  • Zero: Set when the result is zero.
  • Carry: Set if an operation resulted in a carry (addition) into or borrow (subtraction) out of a high order bit.
  • Equal: Set if a logical campare result is equal.
  • Overflow: Used to indicate arithmatic overflow.
  • Interrupt enable/disable: Used to enable or disable interrupts.
  • Supervisor: Indicate whether the CPU is executing in supervisor or user mode.
    Certain privileged instructions can be executed only in supervisor mode, and certain areas of memory can be accessed only in supervisor mode.
Apart from these, a number of other registers related to status and control might be found in a particular CPU design. In addition to the PSW, there may be a pointer to a block of memory containing additional status information (e.g. process control blocks).
Concept of Program Execution
The instructions constituting a program to be executed by a computer are loaded in sequential locations in its main memory. To execute this program, the CPU fetches one instruction at a time and performs the functions specified. Instructions are fetched from successive memory locations until the execution of a branch or a jump instruction.
The CPU keeps track of the address of the memory location where the next instruction is located through the use of a dedicated CPU register, referred to as the program counter (PC). After fetching an instruction, the contents of the PC are updated to point at the next instruction in sequence.
For simplicity, let us assume that each instruction occupies one memory word. Therefore, execution of one instruction requires the following three steps to be performed by the CPU:
  1. Fetch the contents of the memory location pointed at by the PC. The contents of this location are interpreted as an instruction to be executed. Hence, they are stored in the instruction register (IR). Symbolically this can be written as:
                               IR  = [ [PC] ]
                                      
  2. Increment the contents of the PC by 1.
            
                       PC = [PC] + 1
                                     
  3. Carry out the actions specified by the instruction stored in the IR.
 The first two steps are usually referred to as the fetch phase and the step 3 is known as the execution phase. Fetch cycle basically involves read the next instruction from the memory into the CPU and along with that update the  contents of the program counter. In the execution phase, it interpretes the opcode and perform the indicated operation. The instruction fetch and execution phase together known as instruction cycle. The basic instruction cycle is shown in the Figure 5.3.
                                       
                                                         Figure 5.3:
 Basic Instruction cycle
In cases, where an instruction occupies more than one word, step 1 and step 2 can be repeated as many times as necessary to fetch the complete instruction. In these cases, the execution of a instruction may involve one or more operands in memory, each of which requires a memory access. Further, if indirect addressing is used, then additional memory access are required.


 The fetched instruction is loaded into the instruction register. The instruction contains bits that specify the action to be performed by the processor. The processor interpretes the instruction and performs the required action. In general, the actions fall into four categories:
  • Processor-memory: Data may be transfrred from processor to memory or from memory to processor.
                                
  • Processor-I/O: Data may be transferred to or from a peripheral device by transferring between the processor and an I/O module.
                             
  • Data processing: The processor may perform some arithmatic or logic operation on data.
                                      
  • Control: An instruction may specify that the sequence of execution be altered.
The main line of activity consists of alternating instruction fetch and instruction execution activities. After an instruction is fetched, it is examined to determine if any indirect addressing is involved. If so, the required operands are fetched using indirect addressing.
The execution cycle of a perticular instruction may involve more than one reference to memory. Also, instead of  memory references, an instruction may specify an I/O operation. With these additional considerations the basic instruction cycle can be expanded with more details view in the Figure 5.4. The figure is in the form of a state diagram.





No comments:

Post a Comment