如果想要在计算表达式时获得一致和谐的结果,那么控制表达式中的符号就很重要。除了下面描述的内容,系统函数$signed()和$unsigned()用于处理表达式的类型转换。

$signed    //returned value is signed
$unsigned  //returned value is unsigned

例子:$signed和$unsigned。

reg [7:0] regA, regB;
reg signed [7:0] regS;
regA = $unsigned(-4);       // regA = 8'b11111100
regB = $unsigned(-4'sd4);   // regB = 8'b00001100
regS = $signed(4'b1100);    // regS = -4