From: snarflemike@yahoo.com (Mike Silva)
Subject: Is there a better (Ada) way?
Date: 22 Oct 2003 11:56:57 -0700
Date: 2003-10-22T11:56:57-07:00 [thread overview]
Message-ID: <20619edc.0310221056.4c92d10c@posting.google.com> (raw)
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?
next reply other threads:[~2003-10-22 18:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-22 18:56 Mike Silva [this message]
2003-10-22 19:33 ` Is there a better (Ada) way? sk
2003-10-23 18:33 ` Mike Silva
2003-10-22 20:50 ` Robert I. Eachus
2003-10-23 16:57 ` Mike Silva
2003-10-23 21:42 ` Robert I. Eachus
2003-10-24 1:42 ` Mike Silva
2003-10-23 3:12 ` Steve
2003-10-23 18:30 ` Mike Silva
2003-10-24 22:20 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox