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,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-22 11:56:57 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: snarflemike@yahoo.com (Mike Silva) Newsgroups: comp.lang.ada Subject: Is there a better (Ada) way? Date: 22 Oct 2003 11:56:57 -0700 Organization: http://groups.google.com Message-ID: <20619edc.0310221056.4c92d10c@posting.google.com> NNTP-Posting-Host: 154.6.152.68 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1066849017 24130 127.0.0.1 (22 Oct 2003 18:56:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 22 Oct 2003 18:56:57 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:1453 Date: 2003-10-22T11:56:57-07:00 List-Id: 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. Below is a typical question. I need to add a 5-bit signed offset to a 16-bit register. The way I came up with is shown on the last line of the example code, but I want to find out if there's a more Ada-ish way to do what I'm doing. Any comments about any part of the example code are welcome. Mike -------- example code -------- procedure test is type Reg16_t is mod 2**16; -- 16 bit register for Reg16_t'Size use 16; type Offset5_t is range -2**4..2**4-1; -- 5 bit signed offset for Offset5_t'Size use 5; type Dummy_t is mod 2**3; -- just take up extra 3 bits in byte, for this example for Dummy_t'Size use 3; type Postbyte_t is -- typical opcode postbyte record dummy : Dummy_t; offset5 : Offset5_t; end record; for Postbyte_t use record dummy at 0 range 5..7; offset5 at 0 range 0..4; end record; for Postbyte_t'Size use 8; R16 : Reg16_t; PB : Postbyte_t; begin .... R16 := R16 + Reg16_t( Integer( PB.offset5 ) mod Reg16_t'Modulus ); -- the above line works, but is it good Ada, or C-in-Ada?