Hi,
I am trying to use $readmemh in verilog,but i am getting no error.
But, it displays xxxxxxxx value for input and output where I want hex numbers.
My code is as:
Code Verilog - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| module testbench;
reg [31:0] a,b;
reg [2:0] f;
wire [31:0] y;
wire zero;
parameter vecs = 22;
alu alu0 (.a(a),.b(b),.f(f),.y(y),.zero(zero));
reg [100:0] vec [0:vecs-1];
initial
$readmemh("C:\\Users\\Mac\\Desktop\\alu.txt",vec);
integer i;
initial
begin
for (i=0; i<vecs; i=i+1)
//{f,a,b,y,zero}=vec[i];
$display("f=%h, a=%h, b=%h, y=%h, zero=%h",f, a, b, y, zero);
end
endmodule |
this is the testbench for 32 bit ALU. My inputs are 32 bit a and b; f is my 3 bit select. Output is 32 bit y and 1 bit zero.
Zero=1 when output=0 and zero=0 when output=1.
In my program, I want that it will read the hex value from alu.txt and will display the result.
in my text file, the lines are as:
2_00000000_00000000_00000000_1
2_00000000_FFFFFFFF_FFFFFFFF_0
2_00000001_FFFFFFFF_00000000_1 etc; where 2 goes for select bit (here, add operation), next 8 bits are a, b and y respectively. The last one is zero bit.
Problem is whenever, I run the code it shows as:
f=x, a=xxxxxxxx, b=xxxxxxxx, y=xxxxxxxx, zero=x,
f=x, a=xxxxxxxx, b=xxxxxxxx, y=xxxxxxxx, zero=x,
..........................................................................
..........................................................................
Can you please help me to figure out the problem.
Thank you.
Best regards,
Tanvir