From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: How do I use ADA to calculate a checksum?
Date: 1997/09/24
Date: 1997-09-24T00:00:00+00:00 [thread overview]
Message-ID: <01bcc8cf$2e049910$0100007f@dhoossr> (raw)
In-Reply-To: 3427DF0F.4467@scarecrow.gcs.redstone.army.mil
Hi Charles,
For what it's worth, here's how I would go about it, given the
limited "requirements specification.":
-- First, define a type for the checksum.
type Checksum_Type is <implementation-defined>;
-- Perhaps if you're looking for an n-bit checksum, the type would
-- be mod 2 ** N. (See the LRM about modular types)
-- Next, define the checksum function specification:
function Checksum
(Starting_Address : System.Address;
Data_Length : Natural
) return Checksum_Type;
-- Now, we can define the function body:
function Checksum
(Starting_Address : System.Address;
Data_Length : Natural
) return Checksum_Type is
-- Define a "storage unit" type
type Storage_Unit_Type is mod 2 ** System.Storage_Unit;
-- Define the type of an array of these "storage units"
type Storage_Unit_Array_Type is array (1 .. Data_Length) of
Storage_Unit_Type;
-- Define the array of data to be checksummed
Storage_Unit_Array : Storage_Unit_Array_Type;
-- Now, locate the array where the data is
for Storage_Unit_Array'Address use Starting_Address;
-- Define the object to be returned, initialized to zero
The_Checksum : Checksum_Type := 0;
begin
-- Now, the storage elements can be accessed individually -- e.g.,
-- Note that this loop will be executed Data_Length times,
-- even if Dat_Length is 0
for i in Storage_Unit_Array'range loop
--....:=... Storage_Unit_Array (i) .........
end loop;
-- ..........
return The_Checksum;
end Checksum;
There are many good books on Ada95, and I own well over a dozen. But.. if
I had
to limit myself to one it would be Norman Cohen's "Ada as a Second
Language",
Second Edition. You can get it at Madison Books and Computers.
David C. Hoos, Sr.,
david.c.hoos.sr@ada95.com
(205) 726-4965
Charles Phillips <charles@scarecrow.gcs.redstone.army.mil> wrote in article
<3427DF0F.4467@scarecrow.gcs.redstone.army.mil>...
> Hello,
>
> I'm relatively new to ADA95, and would like to ask for assistance
> from those of you who are more knowledgeable.
>
> I have an embedded application which requires me to perform several
> checksum calculations. The question is, when passed a starting
> address and a length, how do I "increment" the address and then
> access the data at the location?
>
> Any help or recommendations with respect to reference books would
> be greatly appreciated.
>
> Charles
>
next prev parent reply other threads:[~1997-09-24 0:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-09-23 0:00 How do I use ADA to calculate a checksum? Charles Phillips
1997-09-23 0:00 ` Tom Moran
1997-09-24 0:00 ` David C. Hoos, Sr. [this message]
1997-09-30 0:00 ` Charles Phillips
1997-09-30 0:00 ` Charles Phillips
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox