Understanding of a program in system verilog

Status
Not open for further replies.

maxxtorr723

Newbie level 5
Joined
Oct 19, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
64
HI,
I am new to system verilog and was trying to simulate the following simple program but am not able to understand how the output is beign generated:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module test ();
initial
  begin
    byte XYZ[4][7];
    foreach(XYZ[i,j])
      XYZ[i][j]=i*100+j;
    foreach (XYZ[i])
      begin
        $write("%d:",i);
        foreach(XYZ[,j])
          $write("%3d",XYZ[i][j]);
                //$display
                end
        end
endmodule



the result that it is generating is
0: 0 1 2 3 4 5 6 1:100101102103104105106 2:-56-55-54-53-52-51-50 3: 44 45 46 47 48 49 50


I am able to understand logic behind 0: 0 1 2 3 4 5 6 1:100101102103104105106 but how 2:-56-55-54-53-52-51-50 3: 44 45 46 47 48 49 50 is coming could someone please explain??
 
Last edited by a moderator:

Because byte is an 8-bit signed integer, and you are assigning it a 32-bit expression i*100+j. The result will overflow and get truncated.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…