Given four 8-bit unsigned inputs, produce both the minimum and the maximum values.
Requirements
minmax4_taskv0[7:0], v1[7:0], v2[7:0], v3[7:0]min_val[7:0], max_val[7:0]Behavior
v0, v1, v2, v3 (all 8-bit unsigned)min_val = minimum of the four, max_val = maximum of the four#, @, wait).output or inout).Syntax
function [WIDTH-1:0] func_name;
input [WIDTH-1:0] a, b; // inputs only
begin
func_name = a + b; // return value
end
endfunction
Usage
assign y = func_name(x, z); // can be used inside expressions
#, @, wait).input, output, inout supported.Syntax
task task_name;
input [7:0] a, b;
output [7:0] sum, diff;
begin
sum = a + b;
diff = a - b;
end
endtask
Usage
task_name(x, y, s, d); // call by name
| Feature | Function | Task |
|---|---|---|
| Return values | One (function name) | Many (via output/inout) |
| Timing controls | ❌ Not allowed | ✅ Allowed |
| Global side effects | ❌ Not allowed | ✅ Allowed |
| Usage in expressions | ✅ Yes (part of continuous/procedural) | ❌ No (must be called as a statement) |
| Synthesis use | Combinational logic | Testbenches, complex procedures |
Quick mnemonic: Use a function when you need a “calculator” (pure math, single return). Use a task when you need a “procedure” (multi-output, delays, events, or side effects).