quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Structure Literals

Structure literals are syntactically similar to C initializers. Structure literals must have a type, either from context or a cast. When an array of structures is initialized, the nested braces should reflect the array and the structure.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - Struct Literals
   

space.gif


  1 `timescale 1ns/100ps
  2 // Type define a struct
  3 typedef struct {
  4   byte a;
  5   reg  b;
  6   shortint unsigned c;
  7 } myStruct;
  8 
  9 module struct_literals ();
 10 
 11 myStruct object = '{10,0,100};
 12 
 13 myStruct objectArray [0:1] = '{'{10,0,100},'{11,1,101}};
 14 
 15 initial begin
 16   $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
 17   object.a = 15;
 18   $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
 19   object.c = 16'hDEAD; 
 20   $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
 21   $display ("Printing array of objects");
 22   $display ("a = %b b = %b c = %h", 
 23      objectArray[0].a, objectArray[0].b, objectArray[0].c);
 24   $display ("a = %b b = %b c = %h", 
 25      objectArray[1].a, objectArray[1].b, objectArray[1].c);
 26    #1  $finish;
 27 end
 28 
 29 endmodule
You could download file struct_literals.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulator Output
   

space.gif

 a = 00001010 b = 0 c = 0064
 a = 00001111 b = 0 c = 0064
 a = 00001111 b = 0 c = dead
 Printing array of objects
 a = 00001010 b = 0 c = 0064
 a = 00001011 b = 1 c = 0065
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com