simulation problem in verilog

Status
Not open for further replies.

NEHA12345

Newbie level 1
Joined
May 11, 2018
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
11
I have coded following verilog code for getting e to the power x. but I am getting only integers. I want answer in real number.How to get it.


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//Expo program
//Expo program
module expo(power,ans,acc);
  input [7:0]power;
  input [7:0]acc;
  output [15:0]ans;
  real [15:0]anstemp;
  real [15:0]temp;
  real [7:0]i; 
 
  always@*
  begin
 
anstemp=1;
temp=1;
 
    for(i=1;i<=acc;i=i+1)
    begin 
      temp=(temp*power)/i; 
anstemp=anstemp+temp;
    end
  end
 
assign ans=anstemp;
endmodule
 
its testbench is as follows.
 
module expotb;
  reg [7:0]power;
  reg [7:0]acc;
  wire [15:0]ans;
 
  expo A1(power,ans,acc);
 
initial
begin 
 
power=5;
acc=10000;
end
 
always @(ans)
  $display( "time =%0t \t output value ans  =%d  ",$time,ans);
endmodule

 

As there is no intention of synthesizing the design (you are writing a program) I would drop using Verilog and do with this in C/C++.

If the intention is to put this on an FPGA the everything you are doing is wrong.
No clock: always @*
for loop programming
real numbers

Verilog is a Hardware Description Language so you are supposed to descripe a digital circuit], not write a software programs.
 

The test bench receives an integer number and displays it using an integer format. Where do you expect a real value?

I wonder which simulator accepts the shown Verilog program. Real is an abstract data type to be used in simulation only and has no bit length. Respectively a declaration like below make no sense.
Code:
real [15:0]anstemp;
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…