Ada语言位域指定

Ada语言位域指定

我们先贴一段代码:

   -- IO地址:WORD型与对应[站号-卡号-通道号]
   type IO_Address(T:Boolean:=True) is record
      case T is
         when True=>
            Addr:word;
         when False=>
            Station:Bit4;
            Card   :Bit4;
            IO     :byte;
      end case;
   end record with Unchecked_Union;
   for IO_ADDRESS use record
      at mod 2;
      Addr at 0 range 0..15;
      Station at 0 range 12..15;
      Card    at 0 range 8..11;
      IO      at 0 range 0..7;
   end record;
   for IO_ADDRESS'size use 16;

这里需要对指定中的at和range进行说明,

AT 从本结构第几个字节开始(初始序标为0) RANGE 从开始字节的第N0(比特)位到第N1个(比特)位。

猜你喜欢

转载自blog.csdn.net/adacore/article/details/82863569