zoukankan      html  css  js  c++  java
  • verilog中的有符号数运算

    verilog中的有符号数运算

    http://hi.baidu.com/lixu1113/item/d00dc095f86aed48f142159a

    verilog中的有符号数运算

    有符号数的计算:若有需要关于有号数的计算,应当利用Verilog 2001所提供的signed及$signed()机制。

    Ex:

    input  signed [7:0] a, b;

    output  signed [15:0] o;

    assign o = a * b;

    or

    input   [7:0] a, b;

    output   [15:0] o;

    wire signed [15:0] o_sgn;

    assisn o_sgn = $signed(a) * $signed(b);

    assign o = $unsigned(o_sgn);

    正负号的扩展:应多加利用Verilog的implicity signed extension,避免手动进行转换。

    Ex:

    input signed [7:0] a, b;

    input signed [8:0] o;

    assign o = a + b; // Verilog会自动进行符号的扩展。有号数与无号数的混合计算:不要在同一个verilog叙述中进行有号数与无号数的计算。应该要分成个别独立的叙述。在一个verilog叙述中只要有一个无号数的操作数,整个算式将被当成无号数进行计算。

    input   [7:0] a;

    input  signed [7:0] b;

    output signed [15:0] o; // Don't do this: assign o = a * b;

    // The $signed({1'b0, a}) can convert the unsigned number to signednumber.a

    ssign o = $signed({1'b0, a}) * b; 

    input signed [7:0] a;output signed [15:0] o; 

    // Don't do this: assign o = a * 8'b10111111;

    // Use $signed() system taskassign o = a * $signed(8'b10111111);

    // or sb keyword.assign o = a * 8'sb10111111;part-select运算过后的操作数是无号数。就算是选择的范围包含整个register或wire。input signed [7:0] a;

    input signed [7:0] b;

    output signed [15:0] o1, o2; // Don't do this:

    assign o1 = a[7:0];assign o1 = a;// Don't do this: assign o2 = a[6:0] * b;

    assign o2 = $signed(a[6:0]) + b

  • 相关阅读:
    Ch5 关联式容器(上)
    Ch4 序列式容器(下)
    Ch4 序列式容器(上)
    DNN模型学习笔记
    关于换博客的说明
    睡前一小时数学之导数的学习与证明
    OpenJudge 666:放苹果 // 瞎基本DP
    OpenJudge 2990:符号三角形 解析报告
    OpenJudge1700:八皇后问题 //不属于基本法的基本玩意
    BZOJ1088扫雷Mine 解析报告
  • 原文地址:https://www.cnblogs.com/touchblue/p/3505800.html
Copyright © 2011-2022 走看看