微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 小题目: 设计一个电路, 求in%3的值

小题目: 设计一个电路, 求in%3的值

时间:10-02 整理:3721RD 点击:
一个小题目, 娱乐一下, 主要针对逻辑设计的新手.
写一个电路, input为a[15:0], output为b[1:0], 求b=a%3, 因为只是实现一段功能, 所以无所谓时序逻辑或组合逻辑, 也不用把整个module都写出来, 当然, 你也可以加上时钟和复位, 但为统一起见, 时钟只用上升沿, 复位为全局异步复位, 低电平有效.
注意是可综合的电路, RTL code, 不是行为级代码 ^_^

看来没人感兴趣, 那就直接把结果贴出来, 免得大家费脑子.
function  [1:0]  mod3_lut4;
    input  [3:0]  a;
    begin
        case(a)
            4'h0:  mod3_lut4 = 2'd0;
            4'h1:  mod3_lut4 = 2'd1;
            4'h2:  mod3_lut4 = 2'd2;
            4'h3:  mod3_lut4 = 2'd0;
            4'h4:  mod3_lut4 = 2'd1;
            4'h5:  mod3_lut4 = 2'd2;
            4'h6:  mod3_lut4 = 2'd0;
            4'h7:  mod3_lut4 = 2'd1;
            4'h8:  mod3_lut4 = 2'd2;
            4'h9:  mod3_lut4 = 2'd0;
            4'ha:  mod3_lut4 = 2'd1;
            4'hb:  mod3_lut4 = 2'd2;
            4'hc:  mod3_lut4 = 2'd0;
            4'hd:  mod3_lut4 = 2'd1;
            4'he:  mod3_lut4 = 2'd2;
            4'hf:  mod3_lut4 = 2'd0;
        endcase
    end
endfunction
function  [1:0]  mod3_byte;
    input  [7:0]  a;
    begin
        mod3_byte = mod3_lut4({mod3_lut4(a[7:4]), mod3_lut4(a[3:0])});
    end
endfunction
input is:   a[15:0]
output is: b[1:0] = mod3_lut4({mod3_byte(a[15:8]), mod3_byte(a[7:0])});

呵呵,有意思,想法很巧妙,顶了

very good

恩,不错。

对我来说 不错 ~

确实不错

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top