comp.lang.ada
 help / color / mirror / Atom feed
* Is there a better (Ada) way?
@ 2003-10-22 18:56 Mike Silva
  2003-10-22 19:33 ` sk
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Mike Silva @ 2003-10-22 18:56 UTC (permalink / 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?



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-10-24 22:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-22 18:56 Is there a better (Ada) way? Mike Silva
2003-10-22 19:33 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox