1

I have a record type as follows:

type Rec_T is record
   a : Bit_12_T;
   b : Bit_4_T;
end record;

where Bit_12_T is mod 2**12 and Bit_4_T is mod 2**4.

To tell the compiler the precise alignment of this record, I use the the for use record statement. However, I want to split the a field bewteen the bytes, so I try to do it as follows:

for Rec_T use record
   a at 0 range 0 .. 7; -- The 1st byte
   a at 1 range 0 .. 3; -- The 2nd byte
   b at 1 range 4 .. 7;
end record;

Clearly, this is not the way to do it as the compiler complains that "component clause is previously given at line ...".

Question: Is it possible to have a component split between the bytes and how to do it? If it is not possible, should I have a_high and a_low and then use some bit operations to merge them together?

NeoSer
  • 527
  • 3
  • 16

1 Answers1

2

Think of the location as an array of bits, not as a sequence of bytes. Hence this should work:

for Rec_T use record
   a at 0 range 0 .. 11; -- bits 0..7 of the 1st byte and bits 0..3 of the 2nd byte
   b at 0 range 12 .. 15; -- bits 4..7 of the second byte
end record;
for Rec_T'Size use 16;

For more information see documentation here, specifically the example at then end of the page, that shows a similar situation.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
Ondrej Tucny
  • 27,626
  • 6
  • 70
  • 90
  • Thank you for the suggestion. I already looked at this example; however, it only shows how to align various fields into bytes and not how to split a single field between bytes. – NeoSer Aug 23 '16 at 08:11
  • 2
    @NeoSer Read the docs again. There's no limitation regarding `first_bit` and `last_bit` belonging to the same byte. Think of the underlying storage as a long, consecutive array of bits. – Ondrej Tucny Aug 23 '16 at 08:29
  • 1
    Ondrej, shouldn’t that be `for Rec_T’Size use 16;`? – Simon Wright Aug 23 '16 at 10:15
  • Yes, one can specify ``for Rec_T'Size use 16;``, but this only tells that the record should fit into 16 bits. In fact, any number of bits can be used, the ones that are not used in ``for Rec_T use record`` will be "marked" as unused. – NeoSer Aug 23 '16 at 10:29