Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a simple task that prints a message.
Verilog
task display_message();
begin
$display([1]);
end
endtaskAttempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the string.
Using single quotes instead of double quotes.
✗ Incorrect
The $display statement requires a string literal enclosed in double quotes.
2fill in blank
mediumComplete the code to call the task 'display_message' inside an initial block.
Verilog
initial begin
[1];
endAttempts:
3 left
💡 Hint
Common Mistakes
Calling the task without parentheses.
Using 'call' keyword which is not used in Verilog.
✗ Incorrect
Tasks are called with parentheses even if they have no arguments.
3fill in blank
hardFix the error in the function definition that returns the sum of two inputs.
Verilog
function integer add_two;
input integer a, b;
begin
add_two = a [1] b;
end
endfunctionAttempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to assign the function name the result.
✗ Incorrect
The function should add the two inputs using the '+' operator.
4fill in blank
hardFill both blanks to complete the task that waits for a signal to be high and then displays a message.
Verilog
task wait_and_display(input signal);
begin
wait (signal [1] 1);
$display([2]);
end
endtaskAttempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' in the wait condition.
Displaying the wrong message.
✗ Incorrect
The task waits until the signal equals 1, then displays the message that the signal is high.
5fill in blank
hardFill all three blanks to complete the function that returns the maximum of two inputs.
Verilog
function integer max_val;
input integer a, b;
begin
if (a [1] b) begin
max_val = [2];
end else begin
max_val = [3];
end
end
endfunctionAttempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Swapping the return values for true and false cases.
✗ Incorrect
The function compares a and b using '>', returns a if true, else returns b.
