hello,
i have a doubt in verilog code..
1)for a given 32 bit input if any one input is also x then return 1 or
else return 0 using functions how do i write a code for this in verilog?
please help
2) for a give 8 bit input if it is divisible by 4 then return 1 else 0..
donot use any arithmetic operators, loop statements ,case statements how
do i do this using functions in verilog
Guest
#2308103
Homework? Which school?
Guest
#2308110
This is just stupid homework. Generations of students figured it out themself. The invoked process is called "learning"... > 2) for a give 8 bit input if it is divisible by 4 then return 1 else 0.. > donot use any arithmetic operators, loop statements ,case statements So far so good. > how do i do this using functions in verilog This is no special problem with verilog. How would you do it in (e.g.) C? I would do it this way: Write down binary numbers and look for a pattern. Which one is devideable by 4? 000000000 * this one 000000001 000000010 000000011 000000100 * this one 000000101 000000110 000000111 000001000 * this one 000001001 000001010 000001011 000001100 * this one 000001101 000001110 000001111 000010000 * this one 000010001 000010010 000010011 000010100 * this one : and so on 111111000 * this one 111111001 111111010 111111011 111111100 * this one 111111101 111111110 111111111 Do you see the pattern? No? Thats your problem. Just a hint: if the lowest 2 bits are '0' the number is divideable by 4. > 1)for a given 32 bit input if any one input is also x then return 1 or > else return 0 using functions how do i write a code for this in verilog? I'm a VHDL guy, but i would use a loop over the 32 bits and compare each of them with 'x'. If one matches, i would terminate the loop an return 1.
The following is the code..everything is fine but the final value is not loaded into the stc..am attaching the simulation screenshots
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 | |
46 | |
47 | |
48 | |
Arjun S. wrote: > The following is the code.. Why the heck did you hijack a 3 year old thread with a completely different topic? > but the final value is not loaded into the stc.. Why should it? I cannot see any assignment to stc.
Reply
Please log in before posting.
