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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3727f1245650af64 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-17 03:52:13 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!feed.news.qwest.net!namche.sun.com!news1brm.central.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: Pascal to ADA Date: 17 Nov 2003 12:41:56 +0100 Organization: Sun Microsystems Message-ID: References: NNTP-Posting-Host: khepri06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1069069316 15390 129.159.112.195 (17 Nov 2003 11:41:56 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 17 Nov 2003 11:41:56 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:2563 Date: 2003-11-17T11:41:56+00:00 List-Id: 1. Why do you need this routine at all? 2. You can accomplish the same in Ada in different ways. two obvious solutions are unchecked_conversion or an overlay with an address clause between a packed array of bytes and your 32 bit integer. Overlay version: type Long_Int is range -2**31 .. 2**31 - 1; type Byte is mod 2**8; ... Procedure Add(N: Long_Int; M: Long_Int; R : out Long_Int) is Cheat_N : array(0..3) of Byte; pragma pack(Cheat_N); for Cheat_N'address use N'address; ... begin ... end Add; 3. Logical operators also work on modular integers. Ada also has arithmetic shift, so you can conveniently access the carry bit. >>>>> "TG" == Tilman Gloetzner writes: TG> Hello, TG> 1) what is a effecient way of rewriting the following code fragement in ADA TG> ? With the absolute keyword, Pascal effectively casts TG> N, M, and R from a 4 byte integer type to an array of 4 bytes by an address TG> access. I guess to implement the same mechanism in TG> ADA is not in line with ADA's philosophy. TG> 2) How do I mask out bits in a (unsigned) number type, as logical operators TG> work only on booleans ? TG> Thank you, TG> Tilman TG> ---------------------------------------------------------------- TG> PROCEDURE Add32(N:LONGINT;M:LONGINT;VAR R:LONGINT) ; TG> VAR TG> _N : ARRAY[0..3] OF BYTE ABSOLUTE N ; TG> _M : ARRAY[0..3] OF BYTE ABSOLUTE M ; TG> _R : ARRAY[0..3] OF BYTE ABSOLUTE R ; TG> A : BYTE ; TG> B : WORD ; TG> C : WORD ; { Carry } TG> BEGIN TG> R := 0 ; TG> C := 0 ; TG> FOR A := 0 TO 3 DO BEGIN TG> B := _N[A] + _M[A] + C ; TG> _R[A] := B AND $FF ; TG> C := B SHR 8 ; TG> END ; TG> END ; -- Strange attractors stole my wife