![]() |
|
|
|||||||
![]() |
VHDL - AND or OR function across a vector |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
I want to implement an OR function across a STD_LOGIC_VECTOR. For
exampe the equivalent of; signal bus : std_logic_vector(3 downto 0); signal result : std_logic; result <= bus(3) or bus(2) or bus(1) or bus(0); rather than typing all the input signals one by one, is there a shorthand notation, or is there a standard package to do so? for example something like "result <= Or(bus);" I have done something like the following but I am not sure if this is the best way to do it. I need to do this since the bus width is a generic parameter and not known before hand. process (bus) begin result <= '0'; for I in bus'Range loop if bus(I) = '1' Or bus(I) = 'H' then result <= '1'; exit; elsif bus(I) = 'X' then result <= 'X'; else null; end if; end loop; end process; Thanks in advance Hitchkas |
|
|
|
|
#2 |
|
Posts: n/a
|
I guess you can very simply do it like this
result <= '1' when bus /= ALL_ZEROS else '0' ; put this declaration in the signal declaration section CONSTANT ALL_ZEROS : std_logic_vector(GENERIC_WIDTH-1 downto 0) := (others => '0') ; Cheers, SK Hitchkas wrote: > I want to implement an OR function across a STD_LOGIC_VECTOR. For > exampe the equivalent of; > > signal bus : std_logic_vector(3 downto 0); > signal result : std_logic; > > result <= bus(3) or bus(2) or bus(1) or bus(0); > > rather than typing all the input signals one by one, is there a > shorthand notation, or is there a standard package to do so? > > for example something like "result <= Or(bus);" > > I have done something like the following but I am not sure if this is > the best way to do it. I need to do this since the bus width is a > generic parameter and not known before hand. > > process (bus) > begin > result <= '0'; > for I in bus'Range loop > if bus(I) = '1' Or bus(I) = 'H' then > result <= '1'; > exit; > elsif bus(I) = 'X' then > result <= 'X'; > else > null; > end if; > end loop; > end process; > > > Thanks in advance > SKeffect |
|
|
|
#3 |
|
Posts: n/a
|
Or:
result <= '0' when bus = (bus'range => '0') else '1'; /Peter Peter |
|
|
|
#4 |
|
Posts: n/a
|
Hitchkas wrote:
> I want to implement an OR function across a STD_LOGIC_VECTOR. For > exampe the equivalent of; > > signal bus : std_logic_vector(3 downto 0); > signal result : std_logic; > > result <= bus(3) or bus(2) or bus(1) or bus(0); > > rather than typing all the input signals one by one, is there a > shorthand notation, or is there a standard package to do so? > > for example something like "result <= Or(bus);" Ah, the reduction-OR operator. One of the few areas where Verilog does something VHDL doesn't. google for "reduction-OR VHDL" -- there's a few examples. -a Andy Peters |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| equivalent function for itoa in Linux gcc compiler | suse | Software | 0 | 03-06-2009 05:30 AM |
| How to assign a returns value of a javascript function to a hiddenfield in a webpart | Chander | Software | 0 | 12-20-2007 09:14 AM |
| How to call C# function in javascript | visj4u | Software | 2 | 04-23-2007 03:24 PM |
| MS Access not recognising Date() function | tessythampan | Software | 0 | 08-28-2006 11:51 AM |
| I lost the "Help and Support" function from my start menu | Keith | A+ Certification | 1 | 03-14-2005 03:05 PM |