How to print '-4', not '11111111111100'

Status
Not open for further replies.

ruwan2

Member level 5
Joined
Nov 29, 2011
Messages
90
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
2,141
Hi,

I read a Verilog tutorial on numeric expression. The example is:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
integer intA;
reg [15:0] regA;
 
always @ * begin
intA = -4'd12;
$display ("\$display: A0 = %b, A0 = %d", intA, intA); // 
 
regA = intA / 3;
$display ("\$display: A1 = %b, A1 = %d", regA, regA); //



The result is:

# $display: A1 = 1111111111111100, A1 = 65532


A1 is -4, but the print is '1111111111111100', or '65532'. It is different from the picture shows.



I find the following but not sign control here.



Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$display("<format>", exp1, exp2, ...);  // formatted write to display
  format indication %b %B binary
                    %c %C character (low 8 bits)
                    %d %D decimal  %0d for minimum width field
                    %e %E E format floating point %15.7E
                    %f %F F format floating point %9.7F
                    %g %G G general format floating point
                    %h %H hexadecimal
                    %l %L library binding information
                    %m %M hierarchical name, no expression
                    %o %O octal
                    %s %S string, 8 bits per character, 2´h00 does not print
                    %t %T simulation time, expression is  $time
                    %u %U unformatted two value data  0 and 1 
                    %v %V net signal strength
                    %z %Z unformatted four value data  0, 1, x, z



It should be able to print '-4' as the picture show. Could you tell me that? Thanks,
 

%b prints binary, %d prints in decimal format. And you want to use reg signed there. In the same way you use "wire signed".
 
Reactions: ruwan2

    ruwan2

    Points: 2
    Helpful Answer Positive Rating
hai
check this document
**broken link removed**

it will help you
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…