What happens between writing a single line of C++ code and observing a signal change inside a digital hardware simulation?

In conventional software, operations are often understood as a sequence of instructions. Hardware, however, introduces another dimension: multiple components can operate concurrently, react to events, and communicate through signals.

Understanding that difference became the starting point for Project #06 of From Lab to Code.

In this project, I built an interactive SystemC Architecture Playground that connects editable C++ models, real hardware simulation, automatic architecture extraction, digital waveforms, and a simplified CPU–memory platform within a single browser-based environment.

The goal was not to build a replacement for professional electronic design automation tools, but to make hardware modeling concepts easier to explore, modify, and understand.

Source code: GitHub — SystemC Architecture Playground

Project series: From Lab to Code · Project website

1. Why SystemC?

C++ is primarily a general-purpose programming language. By itself, it does not provide a hardware-specific simulation model for signals, concurrent processes, and simulation time.

SystemC extends C++ with a class library and an event-driven simulation kernel that makes these concepts available to developers.

Some of its fundamental building blocks are:

  • SC_MODULE — a hardware or system component.
  • sc_in and sc_out — input and output ports.
  • sc_signal — communication between components.
  • SC_METHOD — a process that executes in response to events.
  • SC_THREAD — a process that can suspend and resume execution.
  • sc_start() — execution of the simulation kernel.

These abstractions make it possible to describe systems at different levels, from simple digital logic to higher-level processor and memory architectures.

The interesting question is how to make the relationship between these abstractions and the underlying system behavior visible.

2. What I Built

The playground consists of four interactive experiments:

Experiment Engineering concept
Functional Adder Event-driven arithmetic
Full Adder Boolean logic and intermediate signals
Ripple Carry Adder Hierarchical hardware and carry propagation
CPU / TLM Platform Processor execution and memory transactions

Each experiment includes editable C++ source files, configurable parameters, architecture visualizations, simulation event records, and digital waveforms.

The application uses:

  • C++ and SystemC for actual hardware modeling.
  • Python for the local backend.
  • Docker and GCC for isolated compilation and execution.
  • HTML, CSS, and JavaScript for the interface.
  • Monaco Editor for syntax-highlighted source editing when available.
  • SVG and Canvas for interactive visualizations.

Unlike a browser-only demonstration that reproduces hardware behavior using JavaScript, this application compiles and executes actual SystemC models.

The visualization layer consumes the resulting simulation data.

3. Experiment 01: Functional Adder

The first experiment introduces the relationship between ports, signals, and reactive processes.

The arithmetic operation itself is deliberately simple:

void Adder::compute() { sum.write(a.read() + b.read()); } 

The corresponding process is registered with the SystemC kernel:

SC_METHOD(compute); sensitive << a << b; 

Whenever an input signal changes, the registered method becomes eligible for execution.

For example:

A = 7 B = 5 SUM = 12 

Although the arithmetic is trivial, the execution model is important.

The module does not need a continuous loop that repeatedly checks its inputs. Instead, the SystemC kernel schedules the process in response to signal events.

The playground makes this relationship visible through the source editor, architecture inspector, and recorded simulation events.

4. Experiment 02: From Arithmetic to Digital Logic

A functional addition operation describes what a system calculates, but not necessarily how that calculation is implemented in hardware.

The second experiment moves to a lower abstraction level by implementing a one-bit full adder.

A full adder takes three binary inputs:

  • A
  • B
  • Carry-in

It produces a sum bit and a carry-out bit.

The Boolean equations are:

X = A XOR B SUM = X XOR Cin Cout = (A AND B) OR (X AND Cin) 

Instead of calculating both outputs inside a single process, I separated the implementation into three reactive stages.

void FullAdder::stage1() { x.write(a.read() ^ b.read()); ab.write(a.read() && b.read()); } void FullAdder::stage2() { sum.write(x.read() ^ cin.read()); xc.write(x.read() && cin.read()); } void FullAdder::stage3() { cout.write(ab.read() || xc.read()); } 

This makes intermediate values observable and helps demonstrate how a change in one signal can activate another process.

The expected behavior is defined by the full-adder truth table:

A B Cin Sum Cout
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

The testbench automatically checks all eight combinations after their outputs have settled. It then applies the user's selected inputs so that the final visualization corresponds to the requested experiment.

5. Understanding Delta Cycles

One of the most interesting aspects of SystemC is that multiple events can occur at the same simulation timestamp.

Consider a change in input A of the full adder.

The first process evaluates its logic and requests updates to intermediate signals. Those updates can then activate subsequent processes, which may produce additional signal changes.

Conceptually:

Input changes ↓ Evaluate first logic stage ↓ Update intermediate signals ↓ Evaluate dependent logic stages ↓ Update output signals 

These iterations can occur without advancing physical simulation time.

SystemC uses delta cycles to organize this behavior.

The playground records both:

sc_time_stamp() sc_delta_count() 

This allows the interface to distinguish simulation time from the kernel's delta-cycle count.

Two observations can therefore share the same timestamp while representing different stages of signal propagation.

This is not the same as physical propagation delay through a real transistor or logic gate. The baseline models do not assign artificial physical gate delays.

The purpose is to expose event-driven simulation semantics rather than predict electrical timing.

6. Experiment 03: Building Larger Hardware Through Hierarchy

Once a full adder is available as an independent component, it can be reused to construct a larger arithmetic unit.

A ripple carry adder connects multiple full adders so that the carry output of one stage becomes the carry input of the next.

Cin → FA0 → FA1 → FA2 → FA3 → Cout ↓ ↓ ↓ ↓ S0 S1 S2 S3 

SystemC allows this hierarchy to be expressed using reusable modules and vectors of components.

The core connection logic is:

for (int i = 0; i < n; ++i) { cells[i].a(a[i]); cells[i].b(b[i]); cells[i].cin(carry[i]); cells[i].sum(sum[i]); cells[i].cout(carry[i + 1]); } 

The playground supports four configurable widths:

  • 4 bits
  • 8 bits
  • 16 bits
  • 32 bits

For a simple four-bit example:

 0111 (7) + 0101 (5) ------ 1100 (12) 

A more interesting boundary case is:

 1111 (15) + 0001 (1) ------ 10000 (16) 

In the second example, the carry must propagate across every stage.

The event inspector allows the intermediate carry and sum values to be examined as the model settles. This provides a practical way to understand why hardware hierarchy and signal dependencies matter.

The experiment also checks the resulting arithmetic value against the expected result.

7. Automatic Architecture Extraction

One feature I particularly wanted to explore was the relationship between source code and architecture diagrams.

A predefined diagram can explain an existing circuit, but it becomes less useful when the user changes the implementation.

For that reason, I added a lightweight, pattern-based architecture extractor that analyzes the editable SystemC source files.

It recognizes common structures, including:

  • Module definitions and instances.
  • Input and output ports.
  • Signal declarations and bindings.
  • Registered processes.
  • Direct signal read/write expressions.
  • Vector-based component hierarchies.
  • TLM socket connections.

The extracted information is presented through architecture views, process descriptions, and a connectivity matrix.

For example, changing:

sum.write(a.read() + b.read()); 

to:

sum.write(a.read() - b.read()); 

allows the extracted process description to reflect the modified arithmetic expression.

Likewise, removing a recognized socket binding changes the extracted connectivity.

This creates a useful feedback loop:

Modify source code ↓ Analyze architecture ↓ Compile and simulate ↓ Inspect actual behavior 

An important distinction is that the automatic architecture view is derived from source analysis, whereas the simulation replay is derived from actual recorded execution data.

The extractor is intentionally limited to recognizable SystemC coding patterns. It is not a complete C++ compiler frontend, a hardware synthesis engine, or a general-purpose netlist generator.

8. Experiment 04: CPU and Memory with Transaction-Level Modeling

Digital gates are useful for understanding individual hardware components, but modeling every signal of a larger system can become unnecessarily complex.

Transaction-Level Modeling (TLM) introduces a higher-level communication abstraction.

Instead of describing every individual bus signal, a memory operation can be represented as a transaction containing information such as:

Command: WRITE Address: 0x00 Data: 55 

The final experiment implements a simplified CPU and memory platform using SystemC TLM 2.0.

Its architecture consists of:

  • A CPU acting as a TLM initiator.
  • A memory module acting as a TLM target.
  • Eight 32-bit CPU registers.
  • A small, independently designed instruction set.
  • A 256-byte memory space.
  • Configurable memory transaction latency.

The two components are connected through their sockets:

cpu.socket.bind(mem.socket); 

The CPU sends data transactions using blocking transport:

socket->b_transport(payload, delay); 

The memory target processes the request and annotates the configured delay. The initiator then waits for that simulated duration.

This abstraction makes it possible to investigate the communication and timing behavior of the CPU–memory system without modeling a complete physical bus.

9. Running a Fibonacci Program

To demonstrate processor execution, the CPU experiment includes a small assembly program that calculates the tenth Fibonacci number.

The teaching instruction set supports operations such as:

Instruction Purpose
MOVI Load an immediate value
MOV Copy a register
ADD Add two registers
ADDI Add an immediate value
JNZ Conditional branch
STORE Write data to memory
LOAD Read data from memory
HALT Stop execution

The default program calculates:

Fibonacci(10) = 55 

It then writes the result to memory at address zero and reads it back into register R4.

Memory[0x00] = 55 R4 = 55 

The interface allows users to inspect instructions, register values, memory writes, memory reads, and transaction events.

Memory latency is configurable, making it possible to explore how communication delays affect simulated execution time.

The model deliberately uses a simplified instruction representation. Instructions are parsed into a program vector rather than fetched from TLM memory. Only data accesses use the TLM transport mechanism.

It is therefore an educational processor model, not a cycle-accurate CPU or a complete instruction-fetch architecture.

10. Digital Waveform Visualization

Another important part of hardware debugging is observing how signal values change over time.

SystemC supports waveform tracing using the Value Change Dump (VCD) format.

A trace can be created using:

auto* trace = sc_create_vcd_trace_file("trace"); sc_trace(trace, a, "A"); sc_trace(trace, b, "B"); sc_trace(trace, sum, "SUM"); 

The playground parses the generated VCD file and renders digital waveforms directly in the browser.

Users can:

  • Select individual signals.
  • Zoom into the simulation timeline.
  • Inspect scalar and vector signal changes.
  • Navigate recorded simulation events.
  • Export the original VCD file for external analysis.

The waveform and event inspectors complement each other.

VCD provides a physical simulation-time view, while the event log contains additional recorded information such as delta-cycle counts and processor instructions.

VCD timestamps alone do not necessarily preserve every transition within a single simulation timestamp.

11. Building a Browser-Based SystemC Environment

The application follows a local-first architecture:

Browser-based source editor ↓ Python backend ↓ Docker runner ↓ GCC + SystemC library ↓ Real simulation ↓ VCD + JSON events ↓ Interactive visualizations 

Each experiment separates hardware definitions, implementation files, testbenches, and supporting observation logic.

For example:

full/ ├── FullAdder.h ├── FullAdder.cpp ├── Monitor.h └── main.cpp 

This structure allows users to focus on the actual hardware logic without having to navigate all the instrumentation and test code simultaneously.

Compilation and execution take place inside a restricted, non-root Docker container with resource limits and network access disabled.

The Python backend uses only the standard library, avoiding additional Python package dependencies.

The environment is intended for local educational use. Its container configuration should not be treated as a hardened security boundary for arbitrary untrusted code or public multi-user deployment.

12. Validation and Test Results

To verify the implementation, I included automated tests for the backend, architecture extraction, waveform parsing, input validation, multi-file handling, and actual SystemC execution.

The final local validation produced the following results:

Experiment Result
Python unit tests 7/7 passed
Functional Adder Passed
Full Adder Passed
4-bit Ripple Carry Passed
8-bit Ripple Carry Passed
16-bit Ripple Carry Passed
32-bit Ripple Carry Passed
CPU / TLM Platform Passed

The recorded event counts for the default smoke-test configurations were:

Experiment Recorded events
Functional Adder 3
Full Adder 22
4-bit Ripple Carry 5
CPU / TLM Platform 58

These counts describe the instrumented events recorded during the tested configurations. They are not total kernel scheduling operations, instruction throughput benchmarks, or physical hardware performance measurements.

The CPU test additionally verifies that the Fibonacci result of 55 is written to memory and read back successfully.

13. Try It Yourself

The complete project is available on GitHub:

SystemC Architecture Playground — Source Code

The application requires Python 3.10 or newer and Docker with Linux container support.

Clone the repository:

git clone https://github.com/Ertugrulmutlu/from-lab-to-code.git cd from-lab-to-code/06-systemc-architecture-playground 

Build the SystemC runner:

docker build -t from-lab-to-code-systemc:local . 

Start the application:

python app.py 

Open:

http://127.0.0.1:5058

To reproduce the automated validation:

python -m unittest -v python -m tests.smoke_docker 

Some experiments worth trying:

  • Change the functional adder's arithmetic expression and inspect the extracted process description.
  • Modify a full-adder logic expression and observe whether the truth-table test detects the error.
  • Increase the ripple carry width from 4 to 32 bits.
  • Change the CPU memory latency and compare simulation timestamps.
  • Modify the assembly program and inspect the resulting register and memory states.

A deliberately incorrect implementation may fail its testbench. That is part of the experiment rather than an application error.

14. What This Experiment Taught Me

The most interesting part of this project was seeing how the same system can be understood at multiple abstraction levels.

An arithmetic expression describes a function. A full adder exposes Boolean logic. A ripple carry adder introduces reusable hardware components and hierarchical dependencies. A TLM processor platform introduces communication at the transaction level.

Each abstraction removes certain implementation details while making different engineering questions easier to investigate.

The project also has important limitations:

  • The automatic architecture extractor supports common source patterns rather than arbitrary C++.
  • The architecture views are not synthesized hardware netlists.
  • The CPU uses a compact educational instruction set.
  • The replay shows instrumented simulation events rather than the complete internal kernel scheduler.
  • Simulated timing is not equivalent to measured physical hardware timing.
  • The predefined live visualizations may require adaptation after substantial source-code changes.

Those limitations are intentional. The goal was to make hardware modeling concepts accessible through an environment where source code, architecture, and simulation results can be explored together.

From Lab to Code is my ongoing series of independent engineering projects that connect theoretical concepts with practical implementations, interactive experiments, and reproducible results.

Build. Visualize. Explain.

If you are interested in SystemC, hardware modeling, embedded systems, or transaction-level simulation, the complete implementation and automated tests are available here:

Explore Project #06 on GitHub

Thanks for reading!