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=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 06:42:48 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!nntp-server.caltech.edu!attla2!ip.att.net!attbi_feed3!attbi.com!attbi_s52.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Pascal to ADA X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 12.211.58.135 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s52 1069080167 12.211.58.135 (Mon, 17 Nov 2003 14:42:47 GMT) NNTP-Posting-Date: Mon, 17 Nov 2003 14:42:47 GMT Organization: Comcast Online Date: Mon, 17 Nov 2003 14:42:47 GMT Xref: archiver1.google.com comp.lang.ada:2572 Date: 2003-11-17T14:42:47+00:00 List-Id: This is as close as I can come to a literal translation: subtype BYTE is Unsigned_8; subtype LONGINT is Integer; subtype WORD is Unsigned_16; procedure Add32(N:LONGINT;M:LONGINT;R: in out LONGINT) is N_As_Bytes : array(0..3) of BYTE; for N_As_Bytes'Address use N'Address; M_As_Bytes : array(0..3) of BYTE; for M_As_Bytes'Address use M'Address; R_As_Bytes : array(0..3) of BYTE; for R_As_Bytes'Address use R'Address; B : WORD; C : WORD;-- Carry begin R := 0 ; C := 0 ; for A in 0 .. 3 loop B := WORD( N_As_Bytes(A) + M_As_Bytes(A) ) + C ; R_As_Bytes(A) := BYTE( B and 16#FF# ); C := Shift_Right( B, 8 ); end loop; end Add32; You'll need to have "with Interfaces; use Interfaces" included in order to define Unsigned_8 and Unsigned_16. I changed _N to N_As_Bytes since Ada does not permit using an underscore as the first character in an identifier. Steve (The Duck) "Tilman Gloetzner" wrote in message news:bpa46j$o0l$1@news1.kornet.net... > Hello, > > 1) what is a effecient way of rewriting the following code fragement in ADA > ? With the absolute keyword, Pascal effectively casts > N, M, and R from a 4 byte integer type to an array of 4 bytes by an address > access. I guess to implement the same mechanism in > ADA is not in line with ADA's philosophy. > > 2) How do I mask out bits in a (unsigned) number type, as logical operators > work only on booleans ? > > Thank you, > > Tilman > > ---------------------------------------------------------------- > PROCEDURE Add32(N:LONGINT;M:LONGINT;VAR R:LONGINT) ; > VAR > _N : ARRAY[0..3] OF BYTE ABSOLUTE N ; > _M : ARRAY[0..3] OF BYTE ABSOLUTE M ; > _R : ARRAY[0..3] OF BYTE ABSOLUTE R ; > A : BYTE ; > B : WORD ; > C : WORD ; { Carry } > BEGIN > R := 0 ; > C := 0 ; > FOR A := 0 TO 3 DO BEGIN > B := _N[A] + _M[A] + C ; > _R[A] := B AND $FF ; > C := B SHR 8 ; > END ; > END ; > >