0% found this document useful (0 votes)
51 views

Input Output Wire Function Input Begin End Endfunction Assign Endmodule

The first document defines modules for calculating parity bits, calling functions, and controlling traffic lights using tasks. The second document defines automatic tasks that display values after delays, including blocking and re-entrant tasks. The third document defines a zero-count task that counts the number of zeros in a byte and outputs the count.

Uploaded by

Suvendra Sahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Input Output Wire Function Input Begin End Endfunction Assign Endmodule

The first document defines modules for calculating parity bits, calling functions, and controlling traffic lights using tasks. The second document defines automatic tasks that display values after delays, including blocking and re-entrant tasks. The third document defines a zero-count task that counts the number of zeros in a byte and outputs the count.

Uploaded by

Suvendra Sahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

module parity;

reg[31:0] addr;
regparity;
always @(addr)
begin
parity = calc_parity(addr);
end
function calc_parity;
input [31:0] address;
begin
calc_parity = ^address;
end
endfunction
endmodule

module function_calling(a, b,c);


input a, b ;
output c;
wire c;
function myfunction;
input a, b;
begin
myfunction = (a+b);
end
endfunction
assign c = myfunction (a,b);
endmodule

module traffic_lights;
reg clock, red, amber, green;
parameter on = 1, off = 0, red_tics = 350,
amber_tics = 30, green_tics = 200;

initial red = off;


initial amber = off;
initial green = off;

always begin // sequence to control the lights.


red = on; // turn red light on
light(red, red_tics); // and wait.
green = on; // turn green light on
light(green, green_tics); // and wait.
amber = on; // turn amber light on
light(amber, amber_tics); // and wait.
end
// task to wait for tics positive edge clocks
// before turning color light off.
task light;
output color;
input [31:0] tics;
begin
repeat (tics) @ (posedge clock);
color = off; // turn light off.
end

endtask

always begin // waveform for the clock.


#100 clock = 0;
#100 clock = 1;
end
endmodule // traffic_lights.

module auto_task();

task automatic disp;


input integer a;
input integer d;
begin
#(d) $display("%t d is %d a is %d", $time,d,a);
end
endtask

initial
#10 disp(10,14);

initial
#14 disp(23,18);

initial
#4 disp(11,14);

initial
#100 $finish;

Endmodule

Blocking Task
module tb();
initial
begin
blocking_task();
#5 $display(" Statement after blocking_task at %t ",$time);
end
task blocking_task();
begin
#10;
$display(" statement inside blocking task at %t",$time);
end
endtask
endmodule
RESULTS:
statement inside blocking task at 10
Statement after blocking_task at 15

module re_entrant_task();
2
3 task automatic print_value;
4
input [7:0] value;
5
input [7:0] delay;

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

begin
#(delay) $display("%g Passed Value %d Delay %d", $time, value, delay);
end
endtask
initial begin
fork
#1 print_value (10,7);
#1 print_value (8,5);
#1 print_value (4,2);
join
#1 $finish;
end
endmodule

module zero_count_task (data, out);


input [7:0] data;
output reg [3:0] out;
always @(data)
count_0s_in_byte(data, out);
// task declaration from here
task count_0s_in_byte(input [7:0] data, output reg [3:0] count);
integer i;
begin // task body
count = 0;
for (i = 0; i <= 7; i = i + 1)
if (data[i] == 0) count= count + 1;
end endtask
endmodule

You might also like