From: mheaney@ni.net (Matthew Heaney)
Subject: Re: ada and robots
Date: 1997/06/29
Date: 1997-06-29T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-ya023680002906971441590001@news.ni.net> (raw)
In-Reply-To: 33AAC183.34C0@xtra.co.nz
In article <33AAC183.34C0@xtra.co.nz>, DesignTools@xtra.co.nz wrote:
I'm not a Modula programmer; perhaps you can walk me through some of your
code examples.
>This code uses the BITSET feature of Modula-2, to greate a PACKED
>BOOLEAN
>ARRAY of 24 Data bits, into 3 BYTES.
This can be done in Ada.
type Bit_Array is
array (Positive range 0 .. 23) of Boolean;
for Bit_Array'Size use 24;
for Bit_Array'Component_Size use 1;
or in this case you could just
pragma Pack (Bit_Array);
Ada guarantees that for an array for which the component size is 1 (and
type Boolean is guaranteed to be size 1), that array components are aligned
on contiguous bits.
> CASE BitTimeL OF
> | OneMIN..OneMAX :
> INCL(RxCODE[RxCtr >> 3],RxCtr);
> | ZeroMIN..ZeroMAX : (* default is a Zero *)
> ELSE (* bad value, so reset *)
> TF0 := TRUE; (* catch Reset, next pass *)
> RxCtr := 0;
> END;
> INC(RxCtr);
Can you explain what's going on here?
INCL means add an item to a set, right? If so, you just set the
corresponding bit of the bit array to True.
Of course, we could declare a full-blown set abstract data type,
implemented as a bit array, but when you're twiddling bits anyway, one
doesn't usually bother.
>This code illustrates two methods of loading, one 'collects' BOOLEANs
>and
>is highly readable, the other uses BINARY format.
> IE := {EA,ET0,ES};
> IE := 2#1001_0010; (* EA.EC.ET2.ES.ET1.EX1.ET0.EX0 *)
type Bit_Array_Range is (EA, EC, ET2, ES, ET1, EX1, ETO, EXO);
type Bit_Array is array (Bit_Array_Range) of Boolean;
pragma Pack (Bit_Array);
To do the first, you can use aggregate assignment:
IE : Bit_Array := (EA, ETO, ES => True, others => False);
To do the second, you have to use unchecked conversion:
function To_Bit_Array is
new Unchecked_Conversion (
Source => Interfaces.Unsigned_8,
Target => Bit_Array);
IE : Bit_Array := To_Bit_Array (2#1001_0010#);
Oh well, an extra line of code, to do the instantiation.
>This code is from a DUAL 6 BIT Picket fence D to A converter.
>Total code, for Dual DAC is 95 bytes.
>It allows appx 33KHz clock rates, and can run as a background DAC.
>More, or less, BITS / Channels are easy to add / remove.
>Such DACs are highly linear, use just 1 PIN per DAC, and are ideal for
>integration to control voltage outputs.
> DACa := DAC_A.5; (* Uses BYTE BITADDRESSABLE syntax *)
If you mean get at an individual bit, that can be done if the type is
already declared as a bit array, or else using unchecked_conversion to a
bit array.
DAC_A (5)
or
To_Bit_Array(DAC_A)(5)
You may need an extra pair of parens here; I don't have my Ada 95 compiler
handy.
>This code flips the BIT order in a BYTE, for COMMS protocol usage.
>TYPE hT = ARRAY [0..15] OF BYTE;
> (* 0 1 2 3 4 5 6 7 8 9 A B C D E F
>*)
>CONST MirrorTable =
>hT(0H,08H,04H,0CH,02H,0AH,6,0EH,1,9,5,0DH,3,0BH,7,0FH);
>
>PROCEDURE MirrorF(Par : SHORTCARD REGISTER_2) : SHORTCARD; (* 16
>bytes,14uS *)
>BEGIN
> RETURN(ROTATE(MirrorTable[Par AND 0FH],4) OR MirrorTable[Par >> 4]);
>END MirrorF;
type hT is array (0 .. 15) of Unsigned_8;
-- we may have to declare the array index subtype as a modular type
-- ie type hT is array (Unsigned_8) of Unsigned_8;
-- but I've never done that, and I don't have my compiler handy...
Mirror_Table : constant hT :=
(16#0#, 16#8#, ...);
function Mirror_F (Par : Unsigned_8) return Unsigned_8 is
begin
return Rotate_Right (Mirror_Table (Par and 16#0F#), 4) or
Mirror_Table (Shift_Right (Par, 4));
end;
or something like that.
If my knowledge of Modula were better (I only have Wirth's book, which I
haven't even read), there might be a slicker Ada way to do this, instead of
as a straight translation.
The point is, however, that Ada is no less expressive than Modula with
respect to its low-level facilities. Nor do I suppose its code generation
is any less efficient, if the types in package Interfaces are used.
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
next prev parent reply other threads:[~1997-06-29 0:00 UTC|newest]
Thread overview: 134+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-05-28 0:00 ada and robots John Bohn
1997-05-29 0:00 ` Stephen Leake
1997-05-29 0:00 ` Michael F Brenner
1997-05-30 0:00 ` John Cook
1997-05-30 0:00 ` Tom Moran
1997-06-01 0:00 ` Dale Stanbrough
1997-06-02 0:00 ` John G. Volan
[not found] ` <5mv984$7kn@news.emi.com>
1997-06-03 0:00 ` Martin A. Stembel
1997-06-03 0:00 ` Joe Gwinn
1997-06-04 0:00 ` Pat Rogers
1997-06-05 0:00 ` Joe Gwinn
1997-06-14 0:00 ` Robert Dewar
1997-06-16 0:00 ` Ken Garlington
1997-06-16 0:00 ` Robert Dewar
1997-06-17 0:00 ` Joe Gwinn
1997-06-28 0:00 ` Mike Stark
1997-07-03 0:00 ` Joe Gwinn
1997-06-04 0:00 ` John G. Volan
1997-06-05 0:00 ` Joe Gwinn
1997-06-14 0:00 ` Robert Dewar
1997-06-17 0:00 ` Joe Gwinn
1997-07-03 0:00 ` Shmuel (Seymour J.) Metz
[not found] ` <9706052229.AA29554@jaguar.nmc.ed.ray.com>
1997-06-06 0:00 ` John G. Volan
1997-06-07 0:00 ` RC
1997-06-09 0:00 ` Joe Gwinn
1997-06-05 0:00 ` Jon S Anthony
1997-06-05 0:00 ` Joe Gwinn
1997-06-14 0:00 ` Robert Dewar
1997-06-10 0:00 ` Robert Dewar
1997-06-10 0:00 ` Joe Gwinn
1997-06-11 0:00 ` Robert Dewar
1997-06-12 0:00 ` George Haddad
1997-06-16 0:00 ` Matthew S. Whiting
1997-06-17 0:00 ` Stephen Leake
1997-06-17 0:00 ` Robert A Duff
1997-06-20 0:00 ` jim granville
1997-06-21 0:00 ` Robert Dewar
1997-06-24 0:00 ` Re(dux): Ada for small machines (was Re: ada and robots) Ken Garlington
1997-06-29 0:00 ` Robert Dewar
1997-06-29 0:00 ` Matthew Heaney [this message]
1997-07-03 0:00 ` ada and robots Shmuel (Seymour J.) Metz
1997-07-13 0:00 ` Robert Dewar
1997-06-17 0:00 ` Samuel Mize
1997-06-18 0:00 ` Steve O'Neill
1997-06-19 0:00 ` Anonymous
1997-06-19 0:00 ` Kenneth W. Sodemann
1997-06-20 0:00 ` Stephen Leake
1997-06-20 0:00 ` Robert Dewar
1997-06-17 0:00 ` Jon S Anthony
1997-06-17 0:00 ` Matthew S. Whiting
1997-06-18 0:00 ` Robert A Duff
1997-06-18 0:00 ` Jon S Anthony
1997-06-22 0:00 ` John G. Volan
1997-06-18 0:00 ` Samuel Mize
1997-06-18 0:00 ` Matthew S. Whiting
1997-06-17 0:00 ` Robert Dewar
1997-06-17 0:00 ` Robert A Duff
1997-06-18 0:00 ` Ken Garlington
1997-07-17 0:00 ` Shmuel (Seymour J.) Metz
1997-06-20 0:00 ` Adam Beneschan
1997-06-20 0:00 ` Robert Dewar
1997-06-04 0:00 ` RC
1997-06-04 0:00 ` John G. Volan
1997-06-04 0:00 ` Larry Kilgallen
1997-06-05 0:00 ` Jon S Anthony
1997-06-02 0:00 ` Nick Roberts
1997-06-04 0:00 ` Jan Galkowski
1997-06-05 0:00 ` Albert K. Lee
1997-06-06 0:00 ` dana
1997-06-07 0:00 ` John G. Volan
1997-06-10 0:00 ` dana
-- strict thread matches above, loose matches on Subject: below --
1997-06-05 0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-05 0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-09 0:00 ` Jerry Petrey
1997-06-10 0:00 ` Alan Brain
1997-06-10 0:00 ` Joe Gwinn
1997-06-11 0:00 ` Alan Brain
1997-06-11 0:00 ` Joe Gwinn
1997-06-11 0:00 ` Spam Hater
1997-06-11 0:00 ` Robert Dewar
1997-06-11 0:00 ` Samuel Mize
1997-06-13 0:00 ` Erik Magnuson
1997-06-17 0:00 ` Joe Gwinn
1997-06-18 0:00 ` Jon S Anthony
1997-06-19 0:00 ` Jonathan Guthrie
1997-06-20 0:00 ` Robert Dewar
1997-06-09 0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-12 0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-16 0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-17 0:00 ` Joe Gwinn
1997-06-18 0:00 ` Jon S Anthony
1997-06-18 0:00 ` Brian Rogoff
1997-06-20 0:00 ` Robert Dewar
1997-06-23 0:00 ` Geert Bosch
1997-07-02 0:00 ` Robert Dewar
1997-06-23 0:00 ` Richard Kenner
1997-06-23 0:00 ` Robert Dewar
1997-06-25 0:00 ` Will Rose
1997-06-25 0:00 ` Jonathan Guthrie
1997-06-21 0:00 ` Nick Roberts
1997-06-16 0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-19 0:00 Jon S Anthony
1997-06-19 0:00 ` Brian Rogoff
1997-06-20 0:00 ` Jon S Anthony
1997-06-22 0:00 ` John G. Volan
1997-06-25 0:00 ` Richard A. O'Keefe
1997-06-23 0:00 ` Robert Dewar
1997-06-24 0:00 ` Brian Rogoff
1997-06-20 0:00 Ada " Huy Vo
1997-06-23 0:00 ` Jon S Anthony
1997-06-24 0:00 Huy Vo
1997-06-25 0:00 ` Wes Groleau
1997-06-25 0:00 ` Jon S Anthony
1997-06-25 0:00 ` Dale Stanbrough
1997-06-25 0:00 ` Alan Brain
1997-06-26 0:00 ` Ken Garlington
1997-07-01 0:00 ` Tom Moran
1997-06-26 0:00 Huy Vo
1997-06-27 0:00 ` Jon S Anthony
1997-06-27 0:00 ` Richard A. O'Keefe
1997-06-27 0:00 ` Alan Brain
1997-06-27 0:00 ` Wes Groleau
1997-06-27 0:00 ` Stephen Leake
1997-06-27 0:00 ` nma123
1997-06-27 0:00 ` Wes Groleau
[not found] <867541382.23405@dejanews.com>
1997-06-29 0:00 ` John Howard
1997-06-30 0:00 Huy Vo
1997-07-01 0:00 ` Alan Brain
1997-07-11 0:00 ` Will Rose
1997-07-02 0:00 ` Mattias Sj�sv�rd
1997-07-01 0:00 Huy Vo
1997-07-02 0:00 ` Wes Groleau
1997-07-02 0:00 Huy Vo
1997-07-04 0:00 ` Richard A. O'Keefe
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox