function_task.docx
-
Upload
suvendra-sahoo -
Category
Documents
-
view
215 -
download
0
Transcript of function_task.docx
7/25/2019 function_task.docx
http://slidepdf.com/reader/full/functiontaskdocx 1/5
module parity;
reg[31:0] addr;
regparity;
always @(addr)
begin
parity = calc_parity(addr);
end
unction calc_parity;
input [31:0] address;
begin
calc_parity = !address;
end
endunction
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
7/25/2019 function_task.docx
http://slidepdf.com/reader/full/functiontaskdocx 2/5
module tra"c_lig#ts;
reg cloc$% red% amber% green;
parameter on = 1% o& = 0% red_tics = 3'0%
amber_tics = 30% green_tics = 00;
initial red = o&;
initial amber = o&;
initial green = o&;
always begin se*uence to control t#e lig#ts+
red = on; turn red lig#t on
lig#t(red% red_tics); and wait+
green = on; turn green lig#t on
lig#t(green% green_tics); and wait+
amber = on; turn amber lig#t on
lig#t(amber% amber_tics); and wait+
end
tas$ to wait or tics positi,e edge cloc$s
beore turning color lig#t o&+
tas$ lig#t;
output color;
input [31:0] tics;
begin
repeat (tics) @ (posedge cloc$);
color = o&; turn lig#t o&+
end
7/25/2019 function_task.docx
http://slidepdf.com/reader/full/functiontaskdocx 3/5
endtas$
always begin wa,eorm or t#e cloc$+
-100 cloc$ = 0;
-100 cloc$ = 1;
end
endmodule tra"c_lig#ts+
module auto_tas$();
tas$ automatic disp;
input integer a;
input integer d;
begin
-(d) .display(/t d is d a is d/% .time%d%a);
end
endtas$
initial
-10 disp(10%1);
initial
-1 disp(3%12);
initial
- disp(11%1);
7/25/2019 function_task.docx
http://slidepdf.com/reader/full/functiontaskdocx 4/5
initial
-100 .nis#;
4ndmodule
Blocking Task
module tb();
initial begin
blocking_task();
# 5 $display(" Statement afte blocking_task at !t ",$time);
end
task blocking_task();
begin
# ;
$display(" statement inside blocking task at !t",$time);
end endtask
endmodule
%S&'S
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;
7/25/2019 function_task.docx
http://slidepdf.com/reader/full/functiontaskdocx 5/5
begin 7 !(delay) $display("%g Passed Value %d Delay %d"" $time" value" delay);
# end $ endtask %0%% initial begin
%2 fork %3 #1 print_value (%0"7);
%4 #1 print_value (#"5); %5 #1 print_value (4"2);
% join %7 #1 $finish;
%# end %$20 endmodule
module 5ero_count_tas$ (data% out);
input [6:0] data;
output reg [3:0] out;
always @(data)
count_0s_in_byte(data% out);
tas$ declaration rom #ere
tas$ count_0s_in_byte(input [6:0] data% output reg [3:0] count);
integer i;
begin tas$ body
count = 0;
or (i = 0; i 7= 6; i = i 8 1)
i (data[i] == 0) count= count 8 1;
end endtas$
endmodule