|
A processor includes a set of registers that provide a level of memory that is faster and smaller than main memory. The register in the processor serves two functions:
- User-visible registers
Used by machine or assembly-language programmer for optimizing the register use thereby resulting in a minimum of memory references. For high-level languages, an optimizing compiler will attempt to make intelligent choices of which variables to assign to registers and which to main memory locations.
- Control and status registers
Used by the processor to control the operation of the processor. Moreover it also controls the execution of programs through privileged, operating-system routines.
A clear dividing line between these two register categories cannot be made.
User-visible registers
A user-visible register may be referenced by means of the machine language that the processor executes and is generally available to all programs, including application programs as well as system programs. Types of registers that are typically available are data, address and condition code registers.
Data registers can be assigned to a variety of functions by the programmer. In some cases they are general purpose in nature and can be used with any machine instruction that performs operations on data. Often however there are restrictions.
Address registers contains main memory addresses of data and instructions, or they contain a portion of the address that is used in the calculation of the complete or effective address. These registers may themselves be general-purpose, or they may be devoted to a particular way, or mode of addressing memory. Examples include the following:
- Index Registers
Adding an index to a base value to get the effective address also known as Indexed addressing is a common mode of memory addressing.
- Segment Pointers
With segmented addressing, memory is divided into segments which are variable-length blocks of words. A memory reference consists of a reference to a particular segment and an offset within the segment.
- Stack Pointer
If there is a user-visible stack addressing, then there is a dedicated register that points to the top of the stack. This allows the use of instructions that contain no address field, such as push and pop.
In some routine, a procedure or subroutine call will result in automatic saving of all user-visible registers, to be restored on return. The saving and restoring is performed by the processor as part of the execution of the call and return instructions. This allows each procedure to use these registers independently. On other machines it is the programmer who saves the user-visible register contents before a procedure call. And all this is done by using the relevant instructions in the program. Thus depending on the machine, the saving and restoring functions may be performed either in software or hardware.
Control and Status registers
A variety of processor registers are employed to control the operation of the processor. On most machines most of these are not visible to the user. Some of them may be accessible by machine instructions executed in what is referred to as a control or operating system mode. Off course, different machines will have different register organization and use different terminology. The following registers are essential to instruction execution.
- Program Counter (PC)
contains the address of an instruction to be fetched.
- Instruction Register (IR)
contains the instruction most recently fetched.
All processor designs also include a register or set of registers often known as the program status word (PSW), that contains status information, such as an interrupt enable/disable bit, and a supervisor/user mode bit.
Condition codes (also referred to as flags) are bits set by the processor hardware as the result of operations. For example, an arithmetic operation may produce a positive, negative, zero or overflow result. In addition to the result itself being stored in a register or memory, a condition code is also set following the execution of arithmetic instruction. The code may subsequently be tested as part of a conditional branch operation. Condition code bits are collected in to one or more registers. Usually they form part of a control register. Generally machine instructions allow these bits to be read by implicit reference, but they cannot be altered by explicit reference because they are intended for feedback regarding the results of instruction execution.
In machines using multiple types of interrupts, a set of interrupt registers may be provided with one pointer to each interrupt-handling routine. If a stack is used to implement certain functions, then a system stack pointer is needed.
|