comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <rm-dash-bau-haus@dash.futureapps.de>
Subject: Re: Array slicing question
Date: Mon, 07 Jul 2014 15:34:48 +0200
Date: 2014-07-07T15:34:48+02:00	[thread overview]
Message-ID: <53baa1f7$0$6666$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <91b81cfc-2faa-4cc5-9c9c-0dc663b67a68@googlegroups.com>

On 07.07.14 09:31, Mike Silva wrote:
> I (I being an Ada novice) am still fiddling around with writing 4 bits of LCD display data into a 32-bit GPIO register.  I have this:
>
>     type Bits_1  is mod 2**1 with Size => 1;
>     type Bits_32x1 is array (0 .. 31) of Bits_1 with Pack, Size => 32;
>     type Bits_8x1 is array (0 .. 7) of Bits_1 with Pack, Size => 8;
>
> and I want to do things like this:
>
>     a32 : Bits_32x1;
>     a8  : Bits_8x1;
> ...
>     a32(4..7) := a8(4..7);

Since this expression stays brief only as long as the slices
have no holes in them – and if atomicity of the update is
required, not touching the other bits in a32 – creating
a temporary doesn't seem so bad, perhaps hidden behind
a subprogram serving as abstraction.
   The assignment could not use a simple loop then, either,
so a bit-wise assignment from the components of a8 to components
of a32 seems still more direct than shifts and masks.

My 2¢ (for what might be too general a scheme)

      parent reply	other threads:[~2014-07-07 13:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-07  7:31 Array slicing question Mike Silva
2014-07-07  8:04 ` Simon Wright
2014-07-07 13:34 ` G.B. [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox