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,4ac8a7e7d3e637dc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-22 20:13:00 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.mathworks.com!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!attbi_s54.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <20619edc.0310221056.4c92d10c@posting.google.com> Subject: Re: Is there a better (Ada) way? 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: <%GHlb.1106$mZ5.9467@attbi_s54> NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s54 1066878779 12.211.13.75 (Thu, 23 Oct 2003 03:12:59 GMT) NNTP-Posting-Date: Thu, 23 Oct 2003 03:12:59 GMT Organization: Comcast Online Date: Thu, 23 Oct 2003 03:12:59 GMT Xref: archiver1.google.com comp.lang.ada:1482 Date: 2003-10-23T03:12:59+00:00 List-Id: I don't know if its really more "Ada like" but here is the approach I would take. Rougly following your conventions I would add a type definition: type SReg16_T is range -2**15..2**15-1; for SReg16_T'size use 16; Then use a type conversion for a sign extend: SReg16_T( PB.Offset5 ) And an instance of unchecked conversion to convert to a SReg16_T to a Reg16_T: function To_Reg16_T is new Ada.Unchecked_Conversion( SReg16_T, Reg16_T ); Then the expression in your example would read: R16 := R16 + To_Reg16_T( SReg16_T( PB.Offset5 ) ); Another approach would be to use a lookup table indexed by the offset giving the amount to change the index. Something like: type RegOff_T is array( Offset5_T ) of Reg16_T; Reg_Offset : constant RegOff_T := ( -16 => 16#FFF0#, -15 => 16#FFF1#, -14 => 16#FFF2#, -13 => 16#FFF3#, -12 => 16#FFF4#, -11 => 16#FFF5#, -10 => 16#FFF6#, -9 => 16#FFF7#, -8 => 16#FFF8#, -7 => 16#FFF9#, -6 => 16#FFFA#, -5 => 16#FFFB#, -4 => 16#FFFC#, -3 => 16#FFFD#, -2 => 16#FFFE#, -1 => 16#FFFF#, 0 => 16#0000#, 1 => 16#0001#, 2 => 16#0002#, 3 => 16#0003#, 4 => 16#0004#, 5 => 16#0005#, 6 => 16#0006#, 7 => 16#0007#, 8 => 16#0008#, 9 => 16#0009#, 10 => 16#000A#, 11 => 16#000B#, 12 => 16#000C#, 13 => 16#000D#, 14 => 16#000E#, 15 => 16#000F# ); Then the expression in your example would read: R16 := R16 + Reg_Offset( PB.Offset5 ); If you actually want to try to run the simulator, I'd try a few approaches and pick the one that is faster. BTW: There is a nice module built in to Ada95 called "Interfaces" it defines stuff like Unsigned_16, etc. I prefer to use that over defining my own similar types. Steve (The Duck) "Mike Silva" wrote in message news:20619edc.0310221056.4c92d10c@posting.google.com... > I've started writing a little CPU simulator, just for fun and to be > doing *something* in Ada, and I want to make sure I'm not writing "C > in Ada" when it comes to all the bit, bitfield and register > manipulations. > [snip] > .... > R16 := R16 + Reg16_t( Integer( PB.offset5 ) mod Reg16_t'Modulus ); > -- the above line works, but is it good Ada, or C-in-Ada?