Documentation · Register & Bitfield Maps (reg)
Register & Bitfield Maps
Author hardware bitfields with the reg array across three primary domains: CSR / MMIO registers, ISA instruction specifications (used throughout the official RISC-V specs), and wire/file packet structures.
Use Case 1 · CSR / MMIO
Control & Status Registers
Peripheral control/status registers (CSRs) and memory-mapped I/O (MMIO) registers list fields from LSB (bit 0) to MSB. Pass an array to attr to stack enumerated field values or reset states, and use numeric 0 (or omit name) for reserved bits.
{reg: [
{bits: 1, name: 'EN', attr: 'RW'},
{bits: 1, name: 'IE', attr: 'RW'},
{bits: 2, name: 'MODE', attr: ['IDLE', 'TX', 'RX', 'DUPLEX']},
{bits: 4, name: 'DIV', attr: 'prescaler'},
{bits: 8, name: 0, attr: 'reserved'}
], config: {hspace: 720, bits: 16}}Use Case 2 · ISA Specs
Instruction Formats & Encodings (RISC-V)
Official RISC-V ISA specifications use WaveDrom reg diagrams for three complementary views: (A) individual instruction encodings, (B) stacked instruction formats sharing a common bit ruler, and (C) instruction groups enumerating opcode tables under funct3 / funct7. See Bit-Field Guide →, RISC-V V Opcodes →, and NOP-V →.
{reg: [
{bits: 7, name: 'opcode', attr: 'OP-IMM'},
{bits: 5, name: 'rd', attr: 'dest'},
{bits: 3, name: 'funct3', attr: ['ADDI', 'SLTI', 'ANDI']},
{bits: 5, name: 'rs1', attr: 'src'},
{bits: 12, name: 'imm[11:0]', attr: 'I-immediate'}
], config: {hspace: 720}}{reg: [
// R-type (lane 0)
{bits: 7, name: 'opcode', type: 7},
{bits: 5, name: 'rd', type: 3},
{bits: 3, name: 'funct3', type: 4},
{bits: 5, name: 'rs1', type: 5},
{bits: 5, name: 'rs2', type: 5},
{bits: 7, name: 'funct7', type: 4},
// I-type (lane 1)
{bits: 7, name: 'opcode', type: 7},
{bits: 5, name: 'rd', type: 3},
{bits: 3, name: 'funct3', type: 4},
{bits: 5, name: 'rs1', type: 5},
{bits: 12, name: 'imm[11:0]', type: 6},
// S-type (lane 2)
{bits: 7, name: 'opcode', type: 7},
{bits: 5, name: 'imm[4:0]', type: 6},
{bits: 3, name: 'funct3', type: 4},
{bits: 5, name: 'rs1', type: 5},
{bits: 5, name: 'rs2', type: 5},
{bits: 7, name: 'imm[11:5]', type: 6}
],
config: {
bits: 96,
lanes: 3,
compact: true,
hflip: true,
hspace: 760,
label: {left: ['R-type', 'I-type', 'S-type']}
}}{reg: [
{bits: 7, name: '0110011', attr: 'OP', type: 7},
{bits: 5, name: 'rd', attr: 'dest', type: 3},
{bits: 3, name: 'funct3', type: 4,
attr: ['ADD/SUB', 'SLL', 'SLT', 'SLTU', 'XOR', 'SRL/SRA', 'OR', 'AND']},
{bits: 5, name: 'rs1', attr: 'src1', type: 5},
{bits: 5, name: 'rs2', attr: 'src2', type: 5},
{bits: 7, name: 'funct7', type: 4,
attr: ['0000000 / 0100000', '0000000', '0000000', '0000000', '0000000', '0000000 / 0100000', '0000000', '0000000']}
],
config: {hspace: 760, bits: 32}}Use Case 3 · Wire & File Formats
Packet & Record Structures
Network headers, framing protocols, and binary/ASCII records read left-to-right in transmission order rather than MSB-to-LSB. Set vflip: true to place index 0 on the left, and add a legend to color-code header, payload, and checksum regions. See Motorola S-Record notebook →.
{reg: [
{bits: 1, name: "'S'", attr: 'start (1 char)', type: 7},
{bits: 1, name: 'type', attr: '0..9 (1 char)', type: 4},
{bits: 2, name: 'count', attr: 'byte count (2 hex)', type: 5},
{bits: 4, name: 'address', attr: '16/24/32-bit addr', type: 3},
{bits: 6, name: 'data', attr: 'payload bytes (0..N)', type: 6},
{bits: 2, name: 'csum', attr: '1s-comp (2 hex)', type: 2}
],
config: {
bits: 16,
vflip: true,
hspace: 760,
legend: {Header: 7, Control: 4, Count: 5, Address: 3, Payload: 6, Check: 2}
}}Reference · Options & Quirks
Field Properties & Rendering Options
A few practical quirks to keep in mind: entries in reg always start at bit 0 (LSB) unless vflip: true is set; omitting name draws a shaded reserved box while name: 0 prints a literal zero; hflip: true places lane 0 on top (useful for ascending address offsets like 0x00, 0x04); and rotate: -45 prevents narrow 1–2 bit labels from colliding. Explore all combinations in the Bitfield Testbox →.
| Property | Type | Description |
|---|---|---|
| bits | Number | Bit width of the field (listed LSB to MSB unless vflip: true) |
| name | String | Number | Field label; omit name for shaded unused/reserved gap, or pass 0/1 for constant bits |
| attr | String | Array | Annotations below the field (access mode, reset, or stacked enum/opcode rows) |
| type | Number | Color tint index: 2 red, 3 lime, 4 cyan, 5 amber, 6 green, 7 blue (0–1 gray) |
| rotate | Number | Label rotation angle in degrees (e.g. -45 or -90 for narrow 1–2 bit fields) |
| rect | Object | Extra SVG attributes for the field background |
| Option | Type | Description |
|---|---|---|
| hspace / vspace | Number | Diagram width (default 800) and lane height in px |
| lanes / bits | Integer | Split total bit width across multiple stacked lanes (default 1) |
| compact | Boolean | Stack lanes tightly with shared top bit-index labels |
| hflip / vflip | Boolean | hflip: LSB lane on top; vflip: bit 0 on left (wire/packet byte order) |
| sparse / uneven | Boolean | Draw cage ticks only at field boundaries; handle odd-width last lane |
| trim / offset | Number | Ellipsize long labels (char width px); add integer offset to bit indices |
| legend / label | Object | Top color legend ({Label: type}) and left/right lane labels |
| skin | String | Color skin: default (light) or dark |
{reg: [
{bits: 4, name: 'OP', attr: 'RW', type: 7},
{bits: 2, name: 'EN', rotate: -45, type: 6},
{bits: 2, name: 'IRQ', rotate: -45, type: 5},
{bits: 4},
{bits: 4, name: 'ERR', attr: 'W1C', type: 2},
{bits: 8, name: 'BASE_ADDR_LOW', attr: 'trimmed', type: 4},
{bits: 8, name: 'LIMIT', attr: 'RO', type: 3}
],
config: {
bits: 32,
lanes: 2,
hflip: true,
sparse: true,
trim: 8,
offset: 0,
hspace: 760,
label: {left: ['0x00', '0x04']},
legend: {Control: 6, Fault: 2, Address: 4}
}}