Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple verilog question

Status
Not open for further replies.

sheik_vb

Member level 3
Joined
Jul 21, 2006
Messages
58
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Activity points
1,508
This will report Simulation Error!!!!!!!!!!!!.
 

aji_vlsi

Advanced Member level 2
Joined
Sep 10, 2004
Messages
646
Helped
85
Reputation
170
Reaction score
12
Trophy points
1,298
Location
Bangalore, India
Activity points
4,946
sheik_vb said:
This will report Simulation Error!!!!!!!!!!!!.

Why do you say that? It shouldn't - unless I missed something obvious

Ajeetha, CVC
www.noveldv.com

Added after 1 minutes:

ankit12345 said:
always@(posedg clk)

begin

a<=1;
a<=0;
end



whats the value of a?????

Ankit,
Sounds like an interview question? Why not simulate it and see it for yourself?

Regards
Ajeetha, CVC
www.noveldv.com
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
a=x
as both statements get executed in last simulation time ..
always@(posedge clk)
a<=1;

always@(posedge clk)
a<=0;

this will also result in a=x
 

hyy95120

Member level 1
Joined
Oct 21, 2005
Messages
38
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,522
you should compile this code to logic gates and see what will the result look like.

Simulator is not the final gates.
 

ankit12345

Banned
Joined
Dec 27, 2005
Messages
181
Helped
10
Reputation
20
Reaction score
4
Trophy points
1,298
Location
bangalore,India
Activity points
0
Dear Ajeetha,

ur right.........its interview question........

Any one tried this????????
 

vinod_g

Member level 4
Joined
Nov 29, 2006
Messages
71
Helped
8
Reputation
16
Reaction score
2
Trophy points
1,288
Activity points
1,681
I think it depends on the simulator, whichever the statement executed last will have that value................................
 

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
893
Helped
175
Reputation
350
Reaction score
51
Trophy points
1,308
Activity points
6,843
Code:
always@(posedge clk) 
a<=1; 

always@(posedge clk) 
a<=0;

This will make a=x;

Code:
always@(posedge clk) 

begin 

a<=1; 
a<=0; 
end
In this case a = 0 last driven value!
No need to do sims its a common sense!
 

ankit12345

Banned
Joined
Dec 27, 2005
Messages
181
Helped
10
Reputation
20
Reaction score
4
Trophy points
1,298
Location
bangalore,India
Activity points
0
Wellllllllllllllllllllllllllll......................

my system got hanged when i ran this code......in windows and linux too.............

any one tried???????
 

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
893
Helped
175
Reputation
350
Reaction score
51
Trophy points
1,308
Activity points
6,843
POST ur code here so that we can try it on our end!
 

subramanyam

Member level 3
Joined
Jul 29, 2006
Messages
56
Helped
9
Reputation
16
Reaction score
4
Trophy points
1,288
Location
bengaluru
Activity points
1,660
Code:
always@(posedge clk)
begin
a<=1;
a<=0;
end

In this case a = 0 is the answer and is obvious as is the last executed statement.

Code:
always@(posedge clk)
a<=1;

always@(posedge clk)
a<=0;

when simulated on modelsim the answer is '0'. can anyone run it on other simulators and plz post the answer for this second code.

How the simulator will run the second case ?? and how the answer is different on deifferent simulators ??
 

vlsi_whiz

Full Member level 4
Joined
Nov 12, 2005
Messages
216
Helped
49
Reputation
98
Reaction score
24
Trophy points
1,298
Location
Penang
Activity points
3,139
The answer to this question depends on the simulator... For the first code where the two assignments are done in the same always block the process is as follows:

1. When the code is compiled and simulated, the simulator assigns 1 temporary register for the signal 'a'.
2. During the first tick/time event, the signal 'a' gets the value '1'.
3. In the next tick, the same signal is assigned '0'.
4. Since there are no more assignments after this, the final value is the last assigned value, ie, '0'.
 

deh_fuhrer

Full Member level 5
Joined
Jul 25, 2006
Messages
279
Helped
46
Reputation
92
Reaction score
18
Trophy points
1,298
Activity points
2,874
simulator dependent..a might get the value 0 or may be 1..
 

nmurthy

Member level 1
Joined
Jul 5, 2006
Messages
35
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Location
india
Activity points
1,450
Here a will get the value of 0

As we all know in race between two or more NBA ,last NBA wins
for the case mentioned
a<=1;
a<=0;


hope it helped you
 

cnspy

Full Member level 3
Joined
Sep 10, 2002
Messages
151
Helped
5
Reputation
10
Reaction score
1
Trophy points
1,298
Activity points
1,041
How can you write this kind of code?
 

vinod488

Junior Member level 3
Joined
Dec 20, 2006
Messages
26
Helped
6
Reputation
12
Reaction score
5
Trophy points
1,283
Activity points
1,432
hi,

I Think a<=0 comes out.
Sometimes it depends on simulator which ur using.

Regards,
Vinod
 

verilog_always

Member level 2
Joined
Dec 27, 2006
Messages
43
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
1,552
Code:
always@(posedge clk)
a<=1;

always@(posedge clk)
a<=0;

Can't we get multiple driver problem here?
 

omara007

Advanced Member level 4
Joined
Jan 6, 2003
Messages
1,238
Helped
50
Reputation
102
Reaction score
16
Trophy points
1,318
Location
Cairo/Egypt
Activity points
9,738
No .. it doesn't depend on the simulator .. you sometimes feel that it's simulator dependant because sometimes each simulator has some defaults, but still u can change them ..

The original code will definetly result in : a = 0, regardless of the simulator ... simply because the statements inside the process are sequential .. while outside the process, they are concurrent .. in other words, the signal gets the value of the last assignment, which is '0' in this case ..

On the other hand, you can't assign values to the same signal in 2 different processes .. this is prohibted in RTL .. unless you release the control of the signal from one process to the other .. which is also not adviced, but some designers do it ..
 

satya_422

Member level 3
Joined
Sep 27, 2006
Messages
62
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,594
the result would be a=x because the blocking statements execute concurrently so the both statemts execute simultanoeusly if im not clear please help me



nand_gates said:
Code:
always@(posedge clk) 
a<=1; 

always@(posedge clk) 
a<=0;

This will make a=x;

Code:
always@(posedge clk) 

begin 

a<=1; 
a<=0; 
end
In this case a = 0 last driven value!
No need to do sims its a common sense!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top