Hardware register

Last updated

Internal structure of a basic n-bit register. The associated register-level block diagram symbol is shown on the right. Basic n-bit register.svg
Internal structure of a basic n-bit register. The associated register-level block diagram symbol is shown on the right.

In digital electronics, a register is a group of memory cells that store a collection of bits and continuously output the stored data. [1] [2] It typically consists of a synchronized group of flip-flops in which each flip-flop stores and outputs one bit of the collection. [3] [4] [5] The number of bits a register can store, known as its word size, is equal to the number of flip-flops it contains. [6] [1] It is volatile memory, meaning that the circuit will cease to retain its stored data upon loss of operating power. [6] Registers are characterized in various ways, including by bit storage capacity (e.g., "32-bit register"), signal polarities, logic level and power supply voltages, and timing parameters. [3]

Contents

Registers are a fundamental building block of digital systems. They are used in a diverse range of applications, including in central processing units (CPUs) 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. [6] [3] Its flip-flops share a common clock input which, upon relevant signal edges, causes the flip-flops to sample and store the input data. [3] [5] [7] Typically, the flip-flops also share a common reset input, which is used to initialize the stored data. [4]

Input signals

Output signals

Unused signals

Unused inputs are usually connected to fixed logic levels to prevent them from floating, which might cause unpredictable behavior or damage the register's circuitry.

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:

entityreg32is-- 32 bit register with load enableport(CLK:instd_logic;-- clockRESET:instd_logic;-- async resetLD:instd_logic;-- load enableD:instd_logic_vector(31downto0);-- data inputsQ:outstd_logic_vector(31downto0)-- stored data);endreg32;architecturebehavioralofreg32isbeginprocess(CLK,RESET)beginifRESET='1'then.-- if RESET assertedQ<=(others=>'0');--   zero stored dataelsifrising_edge(CLK)then-- else if CLK active edgeifLD='1'then--   and loading is allowedQ<=D;--     store input dataendif;endif;-- else retain stored dataendprocess;endbehavioral;

In stand-alone MSI integrated circuits, a register is implemented as a semiconductor die which is bonded and encapsulated in a semiconductor package. [8]

Signal visibility

Depending on its implementation and purpose, a register's data inputs and outputs may all be public (accessible to external circuitry), or some data inputs or outputs (or both) 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. [1] 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. [3] 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. [3] 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 (or both) are used to route register outputs onto shared buses. [3] 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 (RAM), by using a memory or port address to select a particular register. [9]

Load enable

In many applications, it is required to load (store new data in) a register only during specific clock cycles and to hold (retain currently stored data) 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 (CE), load enable or simply load (LD) — 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. [4] Instead, to avoid problematic clock skew, the control signal typically is used to manage signal routing to the register's data inputs [4] 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 (or both) 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. [1]

To simplify access and management, related registers are typically organized into groups in which each group is assigned a contiguous range of addresses. [10] 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 (or a single register) to be concurrently gated onto multiple buses; each such instance is commonly called a read port. [6]

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 (RMW) 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 (DMA) 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[15:0]=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.

Interrupt status register

Some register bits are not set or cleared purely as a function of a single data source. An example of this is the circuit shown below, which stores the status of an interrupt request. The flip-flop is set when interrupt service is requested (REQ) by a hardware device (HWI) or software interrupt (SWI), and cleared when the request is acknowledged (ACK). [11] The AND gate prevents a flip-flop clear if a new request arrives while the previous request is being acknowledged, thus ensuring that new requests will not be missed. When both PEND and INTEN (interrupt enable) are active, a service request (IRQ) is sent to the interrupt controller. [11]

The register is addressable via SEL, which typically is driven by an address decoder that maps the register into a processor's memory or I/O address space. The processor can read the register to determine the interrupt request state. When the request is no longer needed, the processor asserts ACK by writing '1' to the register (writing '0' has no effect), thus invoking an atomic clear.

Computers

In computers, typical uses of registers include:

Peripherals

Registers are used in interfaces between software and peripherals. Software writes them to send information to the device, and reads them to receive information from the device.

To read or write a register in a "peripheral unit" (computer hardware outside the CPU), the processor executes a "load" or "store" instruction using the register's memory-mapped I/O or port-mapped I/O address. Registers are accessed in words, but sometimes only use a few bits of the word.

From a CPUs perspective, a register is either read/write, read-only or write-only. The latter is generally not preferred as it can make debugging difficult and prevent read-modify-write operations.

The software-accessible registers in standard integrated circuits typically are documented in their associated electronic component datasheets. Many such devices also have internal registers that are inaccessible to software, which are used for purposes such as state machines and pipelining.

Commercial design tools simplify and automate memory-mapped register specification and code generation for hardware, firmware, hardware verification, testing and documentation. DITA SIDSC XML defines an XML format for memory-mapped registers.

See also

References

  1. 1 2 3 4 Mano, Morris; Ciletti, Michael (2017). Digital Design With an Introduction to the Verilog HDL, VHDL, and SystemVerilog. Pearson. ISBN   978-0134549897.
  2. Maini, Anil (2007). Digital Electronics. Wiley. ISBN   978-0470032145.
  3. 1 2 3 4 5 6 7 8 9 Brown, Stephen; Vranesic, Zvonko (2009). Fundamentals of Digital Logic with VHDL Design. McGraw Hill. ISBN   978-0073529530.
  4. 1 2 3 4 5 Mano, M. Morris. Digital Logic and Computer Design. Pearson. ISBN   978-0132145107.
  5. 1 2 Tanenbaum, Andrew; Austin, Todd (2013). Structured Computer Organization. Pearson. ISBN   978-0132916523.
  6. 1 2 3 4 Patterson, David; Hennessy, John. Computer Organization and Design: The Hardware/Software Interface. Morgan Kaufmann. ISBN   978-0123747501.
  7. Roth, Charles; Kinney, Larry. Fundamentals of Logic Design. Cengage. ISBN   978-1337620352.
  8. Brock, Les (1970). Designing With MSI. Signetics.
  9. Rajaraman, V.; Radhakrishnan, T. (2007-06-01). Computer Organization and Architecture. PHI Learning Pvt. Ltd. p. 38. ISBN   978-8120332003.
  10. Kamal, Raj. Microcontrollers: Architecture, Programming, Interfacing and System Design. Pearson. ISBN   978-8131706978.
  11. 1 2 Stringham, Gary. Hardware/Firmware Interface Design: Best Practices for Improving Embedded Systems Development. Newnes. ISBN   978-1856176057.