From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.226.166 with SMTP id rt6mr7891986obc.47.1403472043464; Sun, 22 Jun 2014 14:20:43 -0700 (PDT) X-Received: by 10.50.43.194 with SMTP id y2mr52127igl.3.1403472043310; Sun, 22 Jun 2014 14:20:43 -0700 (PDT) Path: border1.nntp.dca.giganews.com!nntp.giganews.com!hn18no5935550igb.0!news-out.google.com!qf4ni15igc.0!nntp.google.com!uq10no4605085igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 22 Jun 2014 14:20:42 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=108.69.213.73; posting-account=Rkpt4AoAAAB8fHBAe9UIH5TYP1BQ2uA2 NNTP-Posting-Host: 108.69.213.73 References: <7eaee5fc-2045-4bb3-8b16-d757b54760da@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Cleanest Ada way to do this? From: Mike Silva Injection-Date: Sun, 22 Jun 2014 21:20:43 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: number.nntp.dca.giganews.com comp.lang.ada:187176 Date: 2014-06-22T14:20:42-07:00 List-Id: On Sunday, June 22, 2014 12:07:32 PM UTC-7, Simon Clubley wrote: > On 2014-06-22, Mike Silva wrote: > > > I'd like some help on the cleanest, or most elegant, way to do this in Ada. > > > I'm writing to an LCD character display, in 4-bit mode, which requires writing > > > an 8 bit character or command value as two 4 bit pieces. The port (a memory > > > address) being written to is 32 bits wide. What I would like to be able to do > > > is some form of this (not valid Ada, I know): > > > > > > Port32(4..7) := Some_Char(4..7); > > > ..twiddle some other control bits.. > > > Port32(4..7) := Some_Char(0..3); > > > ..twiddle some other control bits.. > > > > > > > Do the other bits in Port32 need to be preserved when (4..7) are written ? > > > > Is it _required_ that Port32 is written in units of 32 bits ? > > (The answer to that is probably yes, but I thought I would check). > > > > There was some discussion of this class of problem a few weeks ago when > > I was proposing syntax to allow the atomic update of multiple bitfields > > at the same time without having to use an intermediate variables. > > > > The conclusions from that were that if you need to preserve the other > > bits in Port32(4..7) your only real option is to use a temporary > > variable with a 32-bit record structure to match your bitfield > > requirements (unless you want to get into using C style bitmasks.) Yes, the other bits need to be preserved. In C the code would look something like this P32 = (P32 & ~0x00F0) | (c & 0xF0); ...twiddle some control bits P32 = (P32 & ~0x00F0) | ((c << 4) & 0xF0);