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.
204
package my_package;
class Register;
// Properties
logic [7:0] data;
// Methods
function new (logic[7:0] d = 0); // Constructor
data = d;
endfunction
task load (logic[7:0] d);
data = d;
endtask
endclass
// Parameterised classes
class Register1 #(parameter n = 8);
logic [n-1:0] data;
endclass
class Register2 #(parameter type T);
T data;
endclass
// Derived class
class ShiftRegister extends Register;
extern task shiftleft();
extern task shiftright();
endclass
// Out of class method definitions
task ShiftRegister::shiftleft();
data = data << 1;
endtask
task ShiftRegister::shiftright();
data = data >> 1;
endtask
endpackage
module GRG_class1;
import my_package::*;
Register accum; // accum stores a handle to an object of class Register
Register1 #(8) accum1_8 = new; // 8-bit register
Register1 #(.n(16)) accum1_16 = new; // 16-bit register
Register2 #(int) accum2_8 = new; // int register
Register2 #(bit [7:0]) accum2_16 = new; // bit[7:0] register
ShiftRegister SR = new;
initial begin
accum = new; // Create a new Register object; its handle is in accum
accum.data = 8'h1f; // Store value in data member
$display("accum.data = %0h", accum.data);
accum.load(8'h1f); // A better way of doing it
$display("accum.data = %0h", accum.data);
end
initial begin
static Register accum1 = new; // Alternative
static Register accum2 = new(8'hff); // Initialize
static Register accum3[10];
foreach (accum3[i])
accum3[i] = new; // Array of 10 Registers
end
initial begin
SR.load(8'h55); // Inherited method
$display("SR.data = %0h", SR.data);
SR.shiftleft; // data now has 8’aa
$display("SR.data = %0h (after shift left)", SR.data);
end
endmodule
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.