Hardware register
In digital electronics, a register is a group of memory cells that store a collection of bits and continuously output the stored data. It typically consists of a synchronized group of flip-flops in which each flip-flop stores and outputs one bit of the collection. The number of bits a register can store, known as its word size, is equal to the number of flip-flops it contains. It is volatile memory, meaning that the circuit will cease to retain its stored data upon loss of operating power. Registers are characterized in various ways, including by bit storage capacity, signal polarities, logic level and power supply voltages, and timing parameters.
Registers are a fundamental building block of digital systems. They are used in a diverse range of applications, including in central processing units for a variety of purposes; in digital counters and other state machines; in serial and parallel data communications; and in device interfaces for functions such as control and configuration, status reporting, and data buffering.
Signals
A register has a variety of input and output nets, which are the electrical conductors used to convey digital signals between the register and external circuitry.A register has inputs that receive the data to be stored, and outputs that emit the currently stored data. Its flip-flops share a common clock input which, upon relevant signal edges, causes the flip-flops to sample and store the input data. Typically, the flip-flops also share a common reset input, which is used to initialize the stored data.
Input signals
- Reset — initializes all flip-flops to known states, typically '0'. Depending on the register design, this may be synchronous or asynchronous. This is typically used to zero the flip-flops before starting clocked operation.
- Clock — upon rising or falling signal edge, causes the data presented on the data inputs to be stored in the register's flip-flops. In registers that have a synchronous reset input in which reset is asserted, a clock active edge will invoke a register reset in lieu of storing input data.
- Data in — data to be stored upon clock active edge, one bit per flip-flop. For a register with flip-flops, the data inputs are typically named to.
Output signals
- Data out — currently stored data, one bit per flip-flop, continuously emitted, stable except when transitioning to new stored values. For a register with flip-flops, these are typically designated to. Some registers provide both true and complementary data outputs. For example, the 74175 MSI integrated circuit has four flip flops, each with its true and complementary outputs bonded out to package pins.
Unused signals
Unused outputs are typically left unconnected.
Data structure
The data stored in a register may represent any arbitrary binary data that fits into the register's storage capacity. In cases where the data represents a binary integer, the least to most significant data bits are typically associated with register inputs to and outputs to respectively, although this is not required.Implementation
Registers are implemented in various ways, including as stand-alone MSI integrated circuits, as integrated registers within ASICs and programmable processors, and as IP blocks in FPGAs. In the latter case, a register is typically instantiated by synthesizing it from a description written in VHDL, Verilog or some other hardware description language. For example, the following VHDL code describes a 32-bit register with load enable and asynchronous reset:entity reg32 is -- 32 bit register with load enable
port ; -- data inputs
Q : out std_logic_vector -- stored data
);
end reg32;
architecture behavioral of reg32 is
begin
process
begin
if RESET = '1' then. -- if RESET asserted
Q <= ; -- zero stored data
elsif rising_edge then -- else if CLK active edge
if LD = '1' then -- and loading is allowed
Q <= D; -- store input data
end if;
end if; -- else retain stored data
end process;
end behavioral;
In stand-alone MSI integrated circuits, a register is implemented as a semiconductor die which is bonded and encapsulated in a semiconductor package.
Signal visibility
Depending on its implementation and purpose, a register's data inputs and outputs may all be public, or some data inputs or outputs may be designated for internal use only. An example of the latter is a serial-in serial-out shift register, which exposes only one data input and one data output to external circuitry.Applications
In many applications, combinational logic is used to control when and how new data is stored in a register. For example, registers are commonly endowed with a "load enable" function that employs logic gates, in conjunction with a load signal, to allow or inhibit new data to be stored. In a parallel-input shift register, logic gates are used to transfer each stored bit to an adjacent flip-flop, thus shifting the stored binary word by one bit position in a single clock cycle. In a synchronous binary counter, logic gates cause the stored value to step through a binary count sequence.In bus-organized systems, multiplexers or tri-state buffers are used to route register outputs onto shared buses. Common examples of this include register files, peripheral interfaces and multiplexed address/data buses. To facilitate this, address decoders are often used to select one from among a group of registers to input data from, or send stored data to, a shared bus. For example, in computers, peripheral interface registers are often accessed in a fashion similar to random access memory, by using a memory or port address to select a particular register.
Load enable
In many applications, it is required to load a register only during specific clock cycles and to hold during other clock cycles. This is facilitated by adding a "load enable" function to the register, which consists of logic gates and an associated control input — typically called clock enable, load enable or simply load — that allows or inhibits loading depending on its state.A simple way to implement this is to gate the register's clock input with the control signal, but this interferes with system timing because it introduces propagation delay into the clock's signal path. Instead, to avoid problematic clock skew, the control signal typically is used to manage signal routing to the register's data inputs via primitives such as those shown below.
Addressable registers
In bus-oriented systems it is common for registers to receive data from or send stored data to a shared bus. Widely used examples of this include register files and peripheral interface registers. To facilitate this, each register is assigned a unique binary number known as its address, which is used to select the register for read and write operations. The selection mechanism is often based on a 1-of-n binary decoder, which in this capacity is commonly referred to as an address decoder. A register that can be accessed and manipulated using a specific address is said to be an addressable register.To simplify access and management, related registers are typically organized into groups in which each group is assigned a contiguous range of addresses. In general, it is not required for every address in the range to be assigned to a register, and a register may be assigned multiple addresses in the range.
The registers in a group typically share a data input bus for write operations, or a data output bus for read operations, or both. In the latter case, depending on the application, a register group may use separate buses for read and write operations or a single bus for both.
Write operation
In a write operation, a register is selected by sending its address to a binary decoder, which in turn enables the register to store new data. The register's data inputs are connected to and thus receive the data to be stored from a shared bus, as shown in the example circuit below.Read operation
The process of reading an addressable register involves gating its output data onto a shared bus. Depending on the application, the gating mechanism may employ multiplexers or tri-state buffers, or both. The outputs of all registers in a group are accessible to the gating mechanism, thus allowing any register's output word to be sent to the bus. Some applications employ multiple instances of this mechanism to allow different registers to be concurrently gated onto multiple buses; each such instance is commonly called a read port.;Multiplexer gating
In multiplexer-based gating, a register is selected for a read operation by sending its address to a multiplexer. The multiplexer then routes the register's output word to the bus either directly, as shown below, or through a tri-state word buffer in cases where the bus may be driven by other signal sources.
;Tri-state buffer gating
In tri-state buffer-based gating, a register is selected for a read operation by sending its address to a binary decoder, causing the decoder to assert its associated output signal. This signal is sent to a tri-state word buffer, which responds by gating the register's output data onto the bus.
Atomic bit operations
In multitasking systems it is often necessary to set or clear select register bits while leaving others unchanged. This can be accomplished purely by software via a read-modify-write sequence, but if the register is accessed by multiple processes or cores, the integrity of each RMW must be protected using mechanisms such as memory barriers, atomic instructions, and semaphores. The required protection is further complicated if the register can be modified by direct memory access transfers.RMWs and their protection mechanisms can be avoided if the register directly supports atomic operations. Registers endowed with this capability inherently allow specified bits to be set or cleared without the risk of interference from DMA or other processes. This is typically implemented by adding logic to the input of each flip-flop such as in the example below:
In the above circuits, any arbitrary combination of bits can be atomically modified. For example, in the case of a 16-bit register, to atomically set bits 8 and 10, external circuitry would assert LD='1', MODE='1' and D=0x0500.
The MODE inputs may be driven by low order bits of an address bus, thus mapping each of the register's four operations to a unique address. Alternatively, MODE may driven by otherwise unused data bus bits, which allows the register to be mapped to a single address.