quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Packing And Unpacking

Packing performs concatenation of scalars, strings, list elements, or struct fields in the order that you specify. Unpacking performs the reverse operation, splitting a single expression into multiple expressions.

   

space.gif

As part of the concatenation or splitting process, packing and unpacking also perform type conversion between any of the following:

   

space.gif

  • scalars
  • strings
  • lists and list subtypes
   

space.gif

  ../images/main/bulllet_4dots_orange.gif pack()

Packing a scalar expression creates an ordered bit stream by concatenating the bits of the expression together.

Packing are of two types:

   

space.gif

  • packing.low
  • packing.high
   

space.gif

  ../images/main/bullet_star_pink.gif Example - pack()
   

space.gif


  1 <'
  2 struct instruction { 
  3     %opcode     : uint (bits : 3); 
  4     %operand    : uint (bits : 5); 
  5     %address    : uint (bits : 8); 
  6      ! data_packed_high : list of bit; 
  7      ! data_packed_low  : list of bit; 
  8     keep opcode ==  0b100; 
  9     keep operand == 0b11001; 
 10     keep address == 0b00001111; 
 11     post_generate() is also {
 12        data_packed_low = pack(packing.low, opcode, operand); 
 13        data_packed_high = pack(packing.high, opcode, operand);  
 14     };
 15 };
 16 
 17 extend sys {
 18   ins : instruction;
 19   run() is also {
 20     print ins using bin;
 21     print ins.data_packed_low using bin;
 22     print ins.data_packed_high using bin;
 23   };
 24 };
 25 '>
You could download file packing1.e here
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Output - pack()
   

space.gif

  ins = instruction-@0: instruction
	----------------------------------------------	@packing1
0	%opcode:                        0b100
1	%operand:                       0b11001
2	%address:                       0b00001111
3	!data_packed_high:              (8 items)
4	!data_packed_low:               (8 items)
  ins.data_packed_low =  (8 items, bin): 
	                                      1 1 0 0  1 1 0 0  	.0	
  ins.data_packed_high =  (8 items, bin): 
	                                      1 0 0 1  1 0 0 1  	.0	
   

space.gif

  ../images/main/bulllet_4dots_orange.gif unpack()

Unpacking a bit stream into a scalar expression fills the scalar expression, starting by default by putting the lowest bit of the bit stream into the lowest bit of the scalar expression.

   

space.gif

Unpacking are of two types:

   

space.gif

  • packing.low
  • packing.high
   

space.gif

  ../images/main/bullet_star_pink.gif Example - unpack()
   

space.gif


  1 <'
  2 struct instruction { 
  3   %opcode     : uint (bits : 3); 
  4   %operand    : uint (bits : 5); 
  5   %address    : uint (bits : 8); 
  6 };
  7 
  8 extend sys { 
  9   post_generate() is also { 
 10     var inst : instruction; 
 11     var packed_data: list of bit; 
 12     packed_data = {1;1;1;1;0;0;0;0;1;0;0;1;1;0;0;1}; 
 13     unpack(packing.high, packed_data, inst); 
 14     print packed_data using bin;
 15     out("Unpacking high");
 16     print inst using bin;
 17     unpack(packing.low, packed_data, inst); 
 18     out("Unpacking low");
 19     print inst using bin;
 20   }; 
 21 };
 22 '>
You could download file packing2.e here
   

space.gif

  ../images/main/bullet_star_pink.gif Output - unpack()
   

space.gif

  packed_data =  (16 items, bin): 
	                    1 0 0 1  1 0 0 1  0 0 0 0  1 1 1 1  	.0	
Unpacking high
  inst = instruction-@0: instruction
	----------------------------------------------	@packing2
0	%opcode:                        0b100
1	%operand:                       0b11001
2	%address:                       0b00001111
Unpacking low
  inst = instruction-@0: instruction
	----------------------------------------------	@packing2
0	%opcode:                        0b111
1	%operand:                       0b00001
2	%address:                       0b10011001
   

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