CSCE 611 Fall 2026 Lecture 7: SystemVerilog 4
Overview
Jason D. Bakos completes the synthesizable SystemVerilog material for CSCE 611, explaining combinational and clocked `always` blocks, resets, enables, blocking versus nonblocking assignments, and test-bench techniques. He then applies those concepts to RAMs and the RISC-V register file, including asynchronous reads, synchronous writes, two read ports, one write port, register-zero behavior, and a bypass path.
Key takeaways
- Use `always_comb` with complete assignments for combinational logic; missing a branch assignment can infer a latch, while `always_comb` is designed to flag that mistake.
- For the FPGA designs discussed, asynchronous resets can map to native flip-flop reset circuitry and dedicated routing; Bakos’s example contrasted roughly 200 MHz with about 55 MHz for a synchronous-reset implementation.
- Nonblocking assignments model simultaneous clocked state updates: `n1 <= d; q <= n1;` creates two sequential stages because `q` receives the previous value of `n1`.
- A CPU GPIO output needs a register enable so a value remains visible on the seven-segment display until a later instruction changes it.
- The RISC-V register file needs two read ports and one write port to supply two instruction operands and update a destination within a cycle; bypassing handles simultaneous reads and writes to the same nonzero register.
- An asynchronous RAM read can return newly written data as soon as the address selects that location, while a synchronous read adds a clocked operation and a cycle of latency.
Chapters
- `always_comb` describes combinational logic and infers its sensitivity to signals used in the block.
- `always_ff` describes edge-triggered state such as counters, registers, and state machines, typically with `posedge clock`.
- Legacy `always @(...)` syntax is introduced for recognition; `always` without a sensitivity list is reserved for simulation tasks such as generating a test-bench clock.
- An `if` statement or `case` statement used for combinational behavior belongs inside an `always_comb` block.
- Assign every output on every control path; a missing assignment can imply a latch that holds its previous value.
- `always_comb` helps catch incomplete assignments, while a conditional assignment can also be written as a ternary `assign`.
- A four-bit `always_ff` assignment from `D` to `Q` implements a multi-bit register that captures data on a clock edge.
- With no enable, the register captures `D` every cycle, so `Q` reflects the value captured one cycle earlier.
- A hardware register is a bank of flip-flops, distinct from an architectural RISC-V register such as `x1`, which is stored in a register file.
- A synchronous reset is checked inside the clocked block and takes effect only at the next active clock edge; an asynchronous reset is also included in the sensitivity list and can act without a clock edge.
- The shown `if (reset)` condition is active-high; using `if (!reset)` would make the reset active-low.
- Bakos describes an FPGA timing comparison: a CPU using synchronous resets ran at about 55 MHz, versus about 200 MHz for another design using the FPGA flip-flops’ native asynchronous reset.
- The synchronous-reset implementation required extra input logic and ordinary routing, while asynchronous reset could use dedicated high-fan-out FPGA routing.
- An enable lets a register hold its value across cycles instead of capturing new data on every clock edge.
- The CPU’s GPIO output register needs an enable so a display value persists until an instruction updates it, rather than appearing for only one 50 MHz cycle.
- A clocked `if`/`else` structure can implement an up/down counter with reset, increment, decrement, and hold behaviors.
- `<=` is a nonblocking assignment: updates are deferred until the clocked block completes, so later reads in the same block see the old value.
- `=` is a blocking assignment: later statements in the same block see the value assigned earlier.
- With nonblocking assignments, `n1 <= d; q <= n1;` creates two register stages and a two-cycle delay; replacing them with blocking assignments can collapse the intended pipeline behavior.
- Bakos’s course convention is to use `=` for combinational logic and `<=` for clocked `always_ff` logic.
- Simulation needs time to advance between driving inputs and checking outputs; a test bench can use `#` delays or drive on a rising clock edge and check on a falling edge.
- A test-vector file separates test cases from the test-bench engine, with each row holding three binary inputs and one expected output.
- The example test bench loads vectors using `$readmemb`, applies reset, drives inputs on `posedge clock`, and checks results on `negedge clock`.
- The vector array stores test cases by depth and signal bits by width; SystemVerilog declaration syntax places the packed width before the name and the array depth after it.
- Concatenation on the left side of an assignment lets the test bench load several signals, such as `{a, b, c, y_expected}`, from one vector.
- `===` and `!==` compare four-state values including `X` and `Z`, which is useful in test benches; ordinary `==` and `!=` are the hardware-oriented comparisons.
- If a test-vector file has eight rows but the declared array has 10,000 entries, later entries can be `X`; the example uses that condition to detect the end of the vectors.
- Bakos reviews `always_ff`, `always_comb`, and an unclocked `always` loop as the principal block styles needed for the course.
- Simulation tasks include `$readmemh`, `$readmemb`, `$display`, and `$monitor`; `$time` can attach simulation time to diagnostic output.
- A rising-edge detector stores the previous input in `dn_old` and asserts `dout` when the current input is 1 and the delayed value is 0.
- Because clocked nonblocking assignments read old values at the active edge, the detected pulse appears one cycle after the input transition.
- The example maintains `largest` and `second_largest` as values arrive, resetting both to zero when reset is asserted.
- When `dn > largest`, the new input becomes the largest and the old largest becomes second-largest; nonblocking assignments preserve access to that old value.
- When the input is below the largest but greater than `second_largest`, it replaces the second-largest value; repeated values count as separate candidates.
- Comparisons on an unsigned `logic` value are treated as unsigned unless the signal is declared as signed.
- A RAM is organized as addressable rows of fixed-width data; a 1,024-by-32 memory contains 32,768 bits and needs a 10-bit address.
- The CPU uses RAM for both its instruction storage and its RISC-V architectural register file.
- A RAM port accesses only selected entries rather than exposing every stored bit simultaneously, creating the memory-bandwidth bottleneck known as the memory wall.
- The example declares an 8,192-entry memory with 32-bit words, requiring a 13-bit address because `log2(8192) = 13`.
- SystemVerilog places the word width before the memory name and the depth after it, unlike the conventional rows-by-columns description.
- `$readmemh` or `$readmemb` can initialize the memory from a text file before the design accesses it.
- An `assign` from `mem[address]` makes read data respond to address changes without waiting for a clock edge.
- A clocked `always_ff` block with `write_enable` writes `write_data` into `mem[address]` on the active edge.
- Moving the read into a clocked block changes the memory to a synchronous-read design, adding a clocked read operation.
- A RAM port combines address and data access; separate read and write addresses allow operations at different addresses in the same cycle.
- The timing examples write `32'hDEADBEEF` to address 6 and show that an asynchronous read reflects it immediately when address 6 is selected.
- With a synchronous read, the same value appears after the read clock edge, adding roughly one cycle compared with the asynchronous-read example.
- At a clock edge, a clocked block evaluates the old input values, which determines which address and write-enable state the example uses.
- The 32-register RISC-V register file is a 32-by-32-bit RAM, with five-bit addresses because `log2(32) = 5`.
- Two read ports supply the two source operands of an instruction, while one write port updates its destination register.
- Reads are asynchronous and writes are clocked with a write-enable input; instructions that do not update a register leave the write port disabled.
- Reading register `x0` always returns zero, and a bypass path forwards write data when a read and write target the same nonzero register.
Transcript excerpt
0:01 Okay, everyone, let's get started. Any problems with lab 2? Everyone get that turned in last week? Okay, so today I'm going to finish up the lecture on system verilog, which hopefully will get us through all the material you need for the rest of the semester. The, you know, the subset of system verarilog that that that we're going to cover. and then I'm gonna uh talk about the next lab and the uh um design of the risk five micro architecture. So last time I I covered always statements and this is uh I think kind of confusing how this works. Uh I've I've got there's kind of four different types of always always
0:50 statements you can use. Uh there's always comb which is where you you're building combinational logic. It's so you can have u kind of complex like kind of a complex assign statement where you can have if statements, loops, case statements, assign multiple outputs. So for that you you just have always comm and then you put your typically you'll have a begin and end there uh and and then a block of code. Uh and then in the always comm that'll activate whenever any of the inputs change. they they so it sort of takes anything that can be interpreted as an input inside your code and it it assumes those are part of the sensitivity list. Um then there is the always FF which is uh stands for flip-flop and typically these are used for clock logic and most often you'll
1:37 see like pause edge clock in there or neg sometimes you'll see a reset in there as well if it's a asynchronous reset and this is for your clock logic. So this is whenever you have uh counters, memories, registers, and by register I
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Jason D. Bakos.