What the Counter declares
The module declares one clock and one reset. count is an eight-bit unsigned register with reset value zero. The output y reads its current value. The final line describes the next value to store.
Adding one widens the arithmetic result. truncate explicitly converts that result back to the eight-bit destination. When the counter reaches 255, its next stored value wraps to zero.
ZLang source
Public sourcemodule Counter {
clock clk
reset rst
reg count : u8 = 0
out y : u8
y = count
count <- truncate(count + 1)
}
The original example, unchanged from the linked revision.
Compiler check
Recorded outputzlang: ok: examples/counter.zhl (top Counter; syntax and semantics valid)
Recorded process exit status: 0. Syntax and semantic checking only.
Generated SystemVerilog
Recorded output`default_nettype none
module Counter (
input wire logic clk,
input wire logic rst,
output logic [7:0] y
);
// Generated from backend-independent typed ZLang IR.
logic [7:0] count;
always_ff @(posedge clk) begin
if (rst) begin
count <= 8'd0;
end else begin
count <= 8'(({{1{1'b0}}, count} + 9'd1));
end
end
assign y = count;
endmodule
`default_nettype wire
Recorded process exit status: 0. Output file: build/Counter.sv.
Read the compiler result separately from the RTL
The check transcript records a successful syntax and semantic check at compiler revision c768da0bce8b. It confirms that this source passed that compiler's checks. It is not a proof that every possible hardware property holds.
The generated always_ff block updates the register on the rising clock edge. The reset branch loads zero; the other branch stores the truncated sum. The continuous assignment exposes the current register value as y.
Try it locally
Follow Get started for the pinned toolchain and the checked-in event schedule. The website serves recorded files; it does not compile designs or run a simulator.
zlang examples/counter.zhl --top Counter --check
zlang examples/counter.zhl --top Counter --systemverilog build/Counter.svWhat to check next
Simulation exercises the event schedule you supply. Formal results apply to the stated properties and bounds. Synthesis, place and route, and timing analysis require the relevant target tools. A clean compiler check does not replace these steps.
Continue with clocked state and timing, or inspect the larger public examples.
Keep exploring
Counter to SystemVerilog
Read a complete eight-bit design, its recorded semantic check and its generated RTL.
Read the guide →PRACTICAL GUIDEFixed-point arithmetic
Track width and fractional precision through multiplication, rounding and saturation.
Read the guide →PRACTICAL GUIDEClocked state and timing
Separate current-state values, next-state actions, reset behavior and physical timing.
Read the guide →