TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Proportional Font
Show Text Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Content-Transfer-Encoding: quoted-printable
Sender: "Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
From: Carlos Luque Dengra <[log in to unmask]>
Date: Mon, 15 Apr 2002 08:11:18 +0200
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Reply-To: Carlos Luque Dengra <[log in to unmask]>
Parts/Attachments: text/plain (64 lines)
for the development for the port parallel interface, I've planned to map the unsigned_8 value to a record of bits of type (on,off).
Do you know how to mask an integer or unsigned_8?

As far as I haven't found an ellgant way I've done this:

I've the next definitions:

type flag is (on, off);

 type Registro_Byte is
         Bit7 : Flag;
      end record;

data : registro_byte;
register : unsigned_8;

(...) I load an 8-bit integer into the register:

register:= 128; (this is done via DOSPORTS libraries)

I want data to be a map of the register bit:

    if Integer (Shift_Right (register , 0) mod 2 ) = 1 then
         data.Bit0 := On;
         data.Bit0 := Off;
      end if;

    if Integer (Shift_Right (register , 1) mod 2 ) = 1 then
         data.Bit1 := On;
         data.Bit1 := Off;
      end if;

and so on 'til BIT7.

Do you know how to assign the values using a loop?

I don't know how to do a loop that works like the next false one:

for ix in 0..7 loop
  if Integer (Shift_Right (register , ix ) mod 2 ) = 1 then
         data.BIT(ix) := On; -- wrong line
         data.Bit(ix) := Off; -- wrong line
      end if;
end loop;

Thank you in advance.