EDA Playground lets you type in and run HDL code (using a selection of free and commercial simulators and synthesizers).
It's great for learning HDLs, it's great for testing out unfamiliar things and it's great for sharing code.
You can start typing straight away. But to run your code, you'll need to sign or log in. Logging in with a Google account gives you access to all non-commercial simulators and some commercial simulators:
To run commercial simulators, you need to register and log in with a username and password. Registration is free, and only pre-approved email's will have access to the commercial simulators.
209
// Code your testbench here
// or browse Examples
class A;
rand int num[10];
rand int helper[10];
constraint num_c{
foreach(num[i]){
num[i] inside {[0:9]};
}
}
task print_t();
int i = 2;
fork
while(i) begin
#5;
$display("time stamp %t, i=%0d", $time, i);
i--;
end
join_none
endtask
endclass
module top;
initial begin
A a = new();
a.print_t();
$display("outside of the loop, timestamp = %t", $time);
repeat(10) begin
a.randomize();
$display("randomized number: %0p", a.num);
check_un(a.num);
end
end
endmodule
// check the number of unqiue number in a array
function int check_un(int arr[]);
int hash_arr[int];
int unique_arr[$];
int result;
for(int i=0;i<arr.size();i++) begin
if(hash_arr.exists(arr[i])) hash_arr[arr[i]]++;
else hash_arr[arr[i]] = 1;
end
unique_arr = hash_arr.find_index() with (item == 1);
if(unique_arr.size() != 0)
result = unique_arr.size();
else
result = -1;
$display("hash arr is %p", hash_arr);
return result;
endfunction
xxxxxxxxxx
// Code your design here
Your account is not validated. If you wish to use commercial simulators, you need a validated account.
If you have already registered (or have recently changed your email address), but have not clicked on the link in the email we sent you, please do so. If you cannot find the email, please check your spam/junk folder. Or click here to resend the email.
If you have not already registered for a full account, you can do so by clicking below. You will then need to provide us with some identification information. You may wish to save your code first.
Creating, deleting, and renaming files is not supported during Collaboration. To encourage development of these features for Collaboration, tweet to @EDAPlayground
This playground may have been modified. Please save or copy before starting collaboration.
Your exercise has been submitted.