Verilog Commands

🔌 Verilog Commands – Module Basics

TopicQuestionAnswer
VerilogModule declarationmodule name(input clk, output reg q);
VerilogModule with parametersmodule name #(parameter WIDTH=8) (input [WIDTH-1:0] data);
VerilogEndmoduleendmodule
VerilogInput portinput [7:0] data_in
VerilogOutput portoutput [7:0] data_out
VerilogOutput regoutput reg [7:0] result
VerilogInout portinout [7:0] bus
VerilogPort list declarationmodule name(clk, rst, data); input clk, rst; ...
VerilogWire declarationwire [7:0] data;
VerilogMulti-wirewire a, b, c;
VerilogWire with assignmentwire [7:0] result = a + b;
VerilogReg declarationreg [15:0] address;
VerilogInteger declarationinteger count;
VerilogReal declarationreal voltage;
VerilogTime declarationtime current_time;
VerilogParameterparameter WIDTH = 8;
VerilogParameter in moduleparameter WIDTH = 8, DEPTH = 16;
VerilogLocalparamlocalparam DEPTH = 16;
VerilogDefine constant `define MAX_COUNT 100
VerilogInclude file `include "filename.v"
VerilogIfdef conditional `ifdef SYNTHESIS ... `endif
VerilogIfndef `ifndef DEBUG ... `endif
VerilogElse conditional `ifdef SIM ... `else ... `endif
VerilogElsif conditional `ifdef A ... `elsif B ... `endif
VerilogTimescale `timescale 1ns/1ps

🔌 Verilog Commands – Data Types & Operators

TopicQuestionAnswer
VerilogAssign statementassign out = in1 & in2;
VerilogContinuous assignmentassign result = a + b;
VerilogBlocking assignmentdata = 8'hFF;
VerilogNon-blocking assignmentdata <= 8'hFF;
VerilogBinary literal4'b1010
VerilogHex literal8'hFF
VerilogDecimal literal8'd255
VerilogOctal literal8'o377
VerilogUnderscore in literal32'h00FF_00FF
VerilogSigned literal8'sd-5
VerilogConcatenation{a, b, c}
VerilogReplication{4{1'b1}} (creates 4’b1111)
VerilogNested concatenation{a, {2{b}}, c}
VerilogBit selectdata[3]
VerilogPart selectdata[7:4]
VerilogPart select variabledata[base +: 4] or data[base -: 4]
VerilogBitwise ANDa & b
VerilogBitwise ORa | b
VerilogBitwise XORa ^ b
VerilogBitwise XNORa ~^ b or a ^~ b
VerilogBitwise NOT~a
VerilogLogical ANDa && b
VerilogLogical ORa || b
VerilogLogical NOT!a
VerilogEqualitya == b
VerilogInequalitya != b
VerilogCase equalitya === b
VerilogCase inequalitya !== b
VerilogLess thana < b
VerilogGreater thana > b
VerilogLess or equala <= b (context-dependent)
VerilogGreater or equala >= b
VerilogReduction AND&data
VerilogReduction OR|data
VerilogReduction XOR^data
VerilogShift leftdata << 2
VerilogShift rightdata >> 2
VerilogArithmetic shift rightdata >>> 2
VerilogAdditiona + b
VerilogSubtractiona - b
VerilogMultiplicationa * b
VerilogDivisiona / b
VerilogModulusa % b
VerilogPowera ** b
VerilogConditional operatorcondition ? true_val : false_val

🔌 Verilog Commands – Behavioral Constructs

TopicQuestionAnswer
VerilogAlways blockalways @(posedge clk) begin ... end
VerilogAlways combinationalalways @(*) begin ... end
VerilogAlways with resetalways @(posedge clk or negedge rst_n) begin ... end
VerilogIf statementif (condition) begin ... end
VerilogIf-elseif (cond) begin ... end else begin ... end
VerilogIf-else-ifif (c1) ... else if (c2) ... else ...
VerilogCase statementcase (expr) val1: ...; val2: ...; default: ...; endcase
VerilogCasex (don’t care)casex (data) 4'b1xxx: ...; endcase
VerilogCasez (high-Z)casez (data) 4'b1???: ...; endcase
VerilogFor loopfor (i = 0; i < N; i = i + 1) begin ... end
VerilogWhile loopwhile (condition) begin ... end
VerilogRepeat looprepeat (N) begin ... end
VerilogForever loopforever begin ... end
VerilogDisable statementdisable block_name;
VerilogTask definitiontask name; input x; output y; ... endtask
VerilogTask with timingtask name; #10; ... endtask
VerilogCall taskname(arg1, arg2);
VerilogFunction definitionfunction [7:0] name; input [7:0] x; ... endfunction
VerilogFunction automaticfunction automatic [7:0] name(input [7:0] x); ... endfunction
VerilogFunction callresult = name(arg);
VerilogBegin-end blockbegin ... end
VerilogNamed blockbegin: block_name ... end
VerilogFork-join parallelfork ... join
VerilogParallel blockfork ... join

🔌 Verilog Commands – Structural & Generate

TopicQuestionAnswer
VerilogModule instantiationmodule_name inst (.port1(sig1), .port2(sig2));
VerilogPositional instantiationmodule_name inst (sig1, sig2, sig3);
VerilogInstance with parametersmodule_name #(.WIDTH(16)) inst (.clk(clk));
VerilogInstance arraymodule_name inst[3:0] (.in(in), .out(out));
VerilogGenerate forgenerate for (i=0; i<N; i=i+1) begin ... end endgenerate
VerilogGenerate ifgenerate if (WIDTH==8) begin ... end endgenerate
VerilogGenerate casegenerate case (MODE) ... endcase endgenerate
VerilogGenvar declarationgenvar i;
VerilogGenerate block namegenerate for (i=0; i<N; i=i+1) begin: gen_block ... end endgenerate
VerilogSpecify blockspecify ... endspecify
VerilogPath delayspecify (a => b) = 10; endspecify

🔌 Verilog Commands – Memory & Arrays

TopicQuestionAnswer
VerilogMemory arrayreg [7:0] mem [0:255];
Verilog2D memoryreg [7:0] mem [0:15][0:15];
VerilogAccess memorydata = mem[addr];
VerilogWrite memorymem[addr] = data;
VerilogInitialize memoryinteger i; initial for (i=0; i<256; i=i+1) mem[i] = 0;
VerilogMemory sizeparameter DEPTH = 256;

🔌 Verilog Commands – Simulation & System Tasks

TopicQuestionAnswer
VerilogInitial blockinitial begin ... end
VerilogDisplay task$display("Value = %d", data);
VerilogDisplay hex$display("Hex: %h", data);
VerilogDisplay binary$display("Binary: %b", data);
VerilogWrite (no newline)$write("Text");
VerilogMonitor signals$monitor("time=%0t data=%h", $time, data);
VerilogMonitor on/off$monitoron; and $monitoroff;
VerilogStrobe$strobe("Value at end: %d", data);
VerilogFinish simulation$finish;
VerilogFinish with code$finish(2);
VerilogStop simulation$stop;
VerilogSimulation time$time
VerilogReal time$realtime
VerilogScale time$stime
VerilogTime format$timeformat(-9, 2, " ns", 10);
VerilogRead memory hex$readmemh("file.hex", memory);
VerilogRead memory binary$readmemb("file.bin", memory);
VerilogWrite memory hex$writememh("file.hex", memory);
VerilogWrite memory binary$writememb("file.bin", memory);
VerilogRandom number$random
VerilogRandom with seed$random(seed)
VerilogDistribution$dist_uniform(seed, min, max)
VerilogDump file$dumpfile("wave.vcd");
VerilogDump variables$dumpvars(0, top);
VerilogDump on$dumpon;
VerilogDump off$dumpoff;
VerilogDump all$dumpall;
VerilogDump flush$dumpflush;
VerilogDump limit$dumplimit(size);
VerilogFatal error$fatal(1, "Critical error");
VerilogError message$error("Error occurred");
VerilogWarning message$warning("Warning");
VerilogInfo message$info("Information");

🔌 Verilog Commands – Timing & Events

TopicQuestionAnswer
VerilogDelay#10; (10 time units)
VerilogInter-assignment delay#10 data = value;
VerilogIntra-assignment delaydata = #10 value;
VerilogWait statementwait (condition);
VerilogEvent declarationevent event_name;
VerilogTrigger event-> event_name;
VerilogWait for event@(event_name);
VerilogWait posedge@(posedge clk);
VerilogWait negedge@(negedge clk);
VerilogWait any change@(a or b or c);
VerilogWait any change (shorthand)@* or @(*)
VerilogMultiple events@(posedge clk or negedge rst);

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top