
`include "decoder.v"

module top;


integer i,j;

integer seed;


reg [3:0] op1,op2;
reg [2:0] opcode;
reg clk;
reg reset;
wire [3:0] addr,datain,in1,in2;
wire [2:0] ctrl_in;
wire csn,rwn,cin,cout;

reg [3:0] dataout,alu_out;

Instruction_Decoder decoder(.dataout(dataout),.addr(addr),
				.datain(datain),.chipsel(csn),
				.readwrite(rwn),
		
			.ctrl_in(ctrl_in),.in1(in1),.in2(in2),
			.cin(cin), .alu_out(alu_out),
		
			.clk(clk),.reset(reset),
			.op1(op1),.op2(op2),.opcode(opcode));
						
//Ram ram(.dataout(dataout), .addr(addr), .datain(datain), 
//		.csn(csn), .rwn(rwn));
	
//ALU alu(.cout(cout),.f(alu_out),.ctrl_in(ctrl_in),.cin(cin),
//		.in1(in1),.in2(in2),.clk(clk),.reset(reset));

//initial
//$dumpfile("decoder.dmp");

//initial 
//$dumpvars(0,top);

initial
$monitor($time," Decoder says addr=%b, datain=%b, csn=%b, rwn=%b,\n     ctrl_in=%b, in1=%b, in2=%b, cin=%b",addr,datain,csn,rwn,ctrl_in,in1,in2,cin);

initial
begin
	reset = 1'b1;
	clk = 1'b0;
	forever #1 clk = ~clk;
end


initial
begin
	seed = 45;
	
end

initial
$dumpfile("decoder.dmp");

initial 
$dumpvars(0,top);

initial 
begin
i=$random(seed);
	for(i=0;i<8;i=i+1)
	begin
		op1=$random();
		op2=$random();
		opcode=$random();
		dataout = $random();
		alu_out = $random();
		$display("\n\nop1=%b, op2=%b, opcode=%b, dataout=%b, aluout=%b",
					op1,op2,opcode,dataout,alu_out);
		if(opcode==3'b001)
		#20;
		else
		#40;
	end
	#400 $finish;
end


endmodule	
