博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Description of syntax for IF, CASE, WITH and WHEN
阅读量:5782 次
发布时间:2019-06-18

本文共 4031 字,大约阅读时间需要 13 分钟。

1 -- =============================================================================  2 -- file name is:  mux4_1.vhd       (mux=multiplexer)  3 -- Author:        Kim Petersen  4 -- Created:       00.04.10      last modified: 00.04.13  5 -- =============================================================================  6 --  It is a 4 input multiplexer with the function as:  7 --      sel            Input => output     comments  8 --     MSB  LSB  9 --      0    0          in0  => output 10 --      0    1          in1  => output 11 --      1    0          in2  => output 12 --      1    1          in3  => output 13 -- 14 -------- 15 --    IF   and CASE can only be used inside a process. 16 --    WHEN and WITH can only be used outside a process. 17 -- 18 --    IF   corresponds to WHEN 19 --    CASE correpsonds to WITH 20 -- ============================================================================= 21  22 library ieee; 23 use ieee.std_logic_1164.all;      -- can be different dependent on tool used. 24 use ieee.std_logic_unsigned.all;  -- can be different dependent on tool used. 25  26 entity  mux4_1 is 27   port (s0               : in  STD_LOGIC; 28     s1     : in  STD_LOGIC; 29     in0    : in  STD_LOGIC; 30     in1    : in  STD_LOGIC; 31     in2    : in  STD_LOGIC; 32     in3    : in  STD_LOGIC; 33     output : out STD_LOGIC 34   ); 35 end mux4_1; 36 -- ============================================================================= 37 -- ============================================================================= 38 architecture if_example of mux4_1 is 39  40 -- ============================================================================= 41 begin 42  43   mux : process(s0, s1, in0, in1, in2, in3) 44   begin 45  46     if    (s0 = '0' and s1 = '0') then 47       output <= in0; 48     elsif (s0 = '1' and s1 = '0') then 49       output <= in1; 50     elsif (s0 = '0' and s1 = '1') then 51       output <= in2; 52     elsif (s0 = '1' and s1 = '1') then 53       output <= in3; 54     else          -- (s0 or s1 are not 0 or 1) 55       output <= 'X'; 56     end if; 57  58   end process mux; 59  60 end if_example; 61  62 -- ============================================================================= 63 -- ============================================================================= 64 architecture case_example of mux4_1 is 65  66 -- ============================================================================= 67 begin 68  69   mux : process(s0, s1, in0, in1, in2, in3) 70     variable  sel : STD_LOGIC_VECTOR(1 downto 0); 71   begin 72     sel := s1 & s0;   -- concatenate s1 and s0 73  74     case sel is 75       when  "00"  => output <= in0; 76       when  "01"  => output <= in1; 77       when  "10"  => output <= in2; 78       when  "11"  => output <= in3; 79       when others => output <= 'X'; 80     end case; 81  82   end process mux; 83  84 end case_example; 85  86 -- ============================================================================= 87 -- ============================================================================= 88 architecture with_example of mux4_1 is 89  90   signal  sel : STD_LOGIC_VECTOR(1 downto 0); 91 -- ============================================================================= 92 begin 93   sel <= s1 & s0;  -- concatenate s1 and s0 94   with sel  select 95     output <= in0 when "00", 96     in1 when "01", 97     in2 when "10", 98     in3 when "11", 99     'X' when others;100 101 end with_example;102 103 -- =============================================================================104 -- =============================================================================105 architecture when_example of mux4_1 is106 107 -- =============================================================================108 begin109 110   output <= in0 when (s1 & s0) = "00" else111               in1 when (s1 & s0) = "01" else112               in2 when (s1 & s0) = "10" else113               in3 when (s1 & s0) = "11" else114               'X';115 116 end when_example;

转载地址:http://urcyx.baihongyu.com/

你可能感兴趣的文章
HTML5 浏览器返回按钮/手机返回按钮事件监听
查看>>
xss
查看>>
iOS:百度长语音识别具体的封装:识别、播放、进度刷新
查看>>
JS获取服务器时间并且计算距离当前指定时间差的函数
查看>>
华为硬件工程师笔试题
查看>>
jquery居中窗口-页面加载直接居中
查看>>
cd及目录快速切换
查看>>
Unity Shaders and Effects Cookbook (3-5) 金属软高光
查看>>
31-hadoop-hbase-mapreduce操作hbase
查看>>
C++ 代码风格准则:POD
查看>>
linux-友好显示文件大小
查看>>
【转】【WPF】WPF中MeasureOverride ArrangeOverride 的理解
查看>>
【转】二叉树的非递归遍历
查看>>
NYOJ283对称排序
查看>>
接连遇到大牛
查看>>
[Cocos2d-x For WP8]矩形碰撞检测
查看>>
自己写spring boot starter
查看>>
花钱删不完负面消息
查看>>
JBPM之JPdl小叙
查看>>
(step6.1.5)hdu 1233(还是畅通工程——最小生成树)
查看>>