Tutorials
PACKING N UNPACKING
Packing and Unpacking Packing performs concatenation of scalars, strings, list elements, or struct fields in the order that you specifyUnpacking performs the reverse operation, splitting a single expression into multiple expressions.
Packing.High
Places the least significant bit of the last physical field declared or the highest list item at index [0] in the resulting list of bit.
EXAMPLE:
< '
struct instruction {
% opcode : uint ( bits : 3 );
% operand : uint ( bits : 5 );
% address : uint ( bits : 8 );
! data_packed_high : list of bit ;
keep opcode == 0b100 ;
keep operand == 0b11001 ;
keep address == 0b00001111 ;
do_packs () is {
data_packed_high = pack ( packing. high, opcode, operand);
};
};
extend sys {
instruction : instruction;
run () is also {
instruction. do_packs();
print instruction;
print "----------------------------" ;
out ( " %b \n" , instruction. data_packed_high );
}
};
'>
RESULT:
instruction = instruction-@0: instruction
@test
0 %opcode: 4
1 %operand: 25
2 %address: 15
3 !data_packed_high: (8 items)
"----------------------------" = "----------------------------"
%b
1 0 0 1 1 0 0 1
Packing.Low
Places the least significant bit of the first physical field declared or lowest list item at index [0] in the resulting list of bit.
Syntax Example i_stream = pack(packing.high, opcode, operand1, operand2);
EXAMPLE:
< '
struct instruction {
% opcode : uint ( bits : 3 );
% operand : uint ( bits : 5 );
% address : uint ( bits : 8 );
! data_packed_low : list of bit ;
keep opcode == 0b100 ;
keep operand == 0b11001 ;
keep address == 0b00001111 ;
do_packs () is {
data_packed_low = pack ( packing. low, opcode, operand);
};
};
extend sys {
instruction : instruction;
run () is also {
instruction. do_packs();
print instruction;
print "----------------------------" ;
out ( " %b \n" , instruction. data_packed_low );
}
};
'>
RESULT:
instruction = instruction-@0: instruction
@test
0 %opcode: 4
1 %operand: 25
2 %address: 15
3 !data_packed_low: (8 items)
"----------------------------" = "----------------------------"
%b
0 0 1 1 0 0 1 1