logo
1
1
WeChat Login

Verilog Course Project

This is a digital logic design course project based on Verilog, primarily implementing signed comparators and other digital circuit modules.

Project Structure

Course Project 1/
├── source/                  # Source code directory
│   └── signed_compare_comb.v  # Signed comparator
├── testbench/              # Test files directory
│   ├── tb_signed_comparator.v  # Comparator testbench
│   ├── tb_signed_merge_sort4.v
│   └── tb_signed_sort4.v
└── README.md              # This file

Common Verilog Development Commands

1. Compiling Verilog Files

Using Icarus Verilog compiler:

# Basic compilation syntax
iverilog -o output_file source1.v source2.v ...

# Example: Compile comparator module and testbench
iverilog -o test_signed_compare testbench/tb_signed_comparator.v source/signed_compare_comb.v

# Compile single module file (syntax check)
iverilog source/signed_compare_comb.v

2. Running Simulations

Execute compiled simulation files:

# Basic run syntax
vvp compiled_file_name

# Example: Run comparator test
vvp test_signed_compare

# Compile and run directly
iverilog -o test_signed_compare testbench/tb_signed_comparator.v source/signed_compare_comb.v && vvp test_signed_compare

3. Output Processing Commands

View and process simulation outputs:

# View complete output
vvp test_signed_compare

# View first 50 lines
vvp test_signed_compare | head -50

# View last 5 lines
vvp test_signed_compare | tail -5

# Find error messages
vvp test_signed_compare | grep "ERROR"

# Count number of errors
vvp test_signed_compare | grep "ERROR" | wc -l

# Save output to file
vvp test_signed_compare > simulation_output.txt

# Show only passes and failures
vvp test_signed_compare | grep -E "(PASS|ERROR)"

4. Project Navigation Commands

Quick navigation in project directory:

# Enter project directory
cd "/workspace/Course Project 1"

# View project structure
tree .
# or
find . -name "*.v" -type f

# View all Verilog files
ls -la source/*.v testbench/*.v

# Search content in files
grep -r "module" source/ testbench/
grep -r "parameter" source/
grep -r "assign" source/

5. Common Development Workflow

Complete development and testing workflow:

# 1. Enter project directory
cd "/workspace/Course Project 1"

# 2. Check code syntax
iverilog source/your_module.v

# 3. Compile and run tests
iverilog -o test_module testbench/tb_your_module.v source/your_module.v
vvp test_module

# 4. View test results
vvp test_module | grep -E "(PASS|ERROR)" | tail -10

# 5. If there are errors, view detailed error information
vvp test_module | grep "ERROR" -A 2 -B 2

6. Debugging

# View detailed compilation information
iverilog -v source/your_module.v

# Generate detailed simulation report
vvp -v test_module

# View specific pattern messages
vvp test_module | grep -E "(num_a=.*num_b=.*ERROR|PASS.*)"

# Count number of test cases
vvp test_module | wc -l

Module Description

signed_compare_comb.v - Signed Comparator

Function: Compare the magnitude of two signed numbers

Parameters:

  • WIDTH: Bit width of operands (default is 4 bits)

Ports:

  • num_a[WIDTH-1:0]: Number to compare A
  • num_b[WIDTH-1:0]: Number to compare B
  • greater_than: Comparison result (1 means A > B, 0 means A ≤ B)

Features:

  • Pure combinational logic implementation
  • Only uses bitwise operators (&, |, ~, ^)
  • No comparison operators (<, >, <=, >=)
  • No arithmetic operators (+, -)

tb_signed_comparator.v - Testbench

Function: Automatically test all input combinations of the comparator

Test Range:

  • 4-bit signed numbers: -8 to +7
  • Total 16×16 = 256 test cases

Output Format:

  • PASS: Test passed
  • ERROR: Test failed, shows expected and actual values

About

数字逻辑大作业

Language
Verilog51.4%
Assembly39.7%
C++3.2%
Others5.7%