comp.lang.ada
 help / color / mirror / Atom feed
* RISC
@ 2001-03-14 20:23 chris.danx
  2001-03-14 21:57 ` RISC Tucker Taft
                   ` (4 more replies)
  0 siblings, 5 replies; 82+ messages in thread
From: chris.danx @ 2001-03-14 20:23 UTC (permalink / raw)


Hi,
    I'm simulating a RISC machine in Ada.  Eventually the instructions will
be mapped to native architecture (x86, m68xxx, SPARC, etc), but for now i
want to simulate a machine, to limit the possibility of doing something
nasty to anyone's machine.

I've decided to provide byte, word and long word  modes for most
instructions.  The problem comes when clearing or setting byte or word
portions of a register (the machine is loosely based on M68000).  The
register is long word (32bit) and i want to set the lower 16bits or 8bits.
I've managed to get this to work, problem is it's not very efficient.

The register is of type 'mod', so i divided by 2**8 or 2**16 then multiplied
by it.  I know multiplication and division are costly and really i'm looking
for something more efficient.  If this were Pascal i'd use 'shift
left/right' which is quite fast.  What should i do to speed it up?  Does Ada
have a shift L/R operation?  Is there another way to do it?

I have another problem with memory.  I thought about allocating one big
block of memory (as an array) and accessing it by index.  The problem?  I do
plan to dynamically allocate the memory, but i'll still be limited by the
amount of memory allocable in a single array.  I've thought of a few ways of
doing this but can't seem to avoid problems!  Anyone know of a solution?  I
don't like using C, but i 'd run in to a similar problem binding with C
anyway.


Thanks,
Chris Campbell

p.s. This isn't a homework assignment!!!





^ permalink raw reply	[flat|nested] 82+ messages in thread
* RE: RISC
@ 2001-03-16 23:25 Beard, Frank
  2001-03-17 11:39 ` RISC chris.danx
  0 siblings, 1 reply; 82+ messages in thread
From: Beard, Frank @ 2001-03-16 23:25 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

> Does Ada have routines for displaying numbers in Hex or Octal (preferably
> Hex)?

For integers, use the Integer_Io generic in Text_Io:

   package Int_Io is new Ada.Text_Io.Integer_Io(integer);

Procedure Put has the following spec:

   procedure Put(Item  : in Num;
                 Width : in Field := Default_Width;
                 Base  : in Number_Base := Default_Base);

So,

      x : integer := 10;

   begin

      Int_Io.Put(item => x,
                 base => 16);

Outputs an A.

For Modular types, use the Modular_Io generic in Text_Io.

   type Byte is mod 2**8;
   package Mod_Io is new Ada.Text_Io.Modular_Io(Byte);

Procedure Put is defined the same way, as:

   procedure Put(Item  : in Num;
                 Width : in Field := Default_Width;
                 Base  : in Number_Base := Default_Base);

So,

      x : Byte := 10;

   begin

      Mod_Io.Put(item => x,
                 base => 16);

Frank




^ permalink raw reply	[flat|nested] 82+ messages in thread
* RE: RISC
@ 2001-03-29  3:12 Beard, Frank
  2001-03-29  7:28 ` RISC Martin Dowie
                   ` (2 more replies)
  0 siblings, 3 replies; 82+ messages in thread
From: Beard, Frank @ 2001-03-29  3:12 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

Chris,

I haven't been following the thread and someone may have
already suggested this, but, along the lines of what Martin
was suggesting, can't you do the following:

   For addition:

      Register := ...

      New_Value := Register + delta;

      if (New_Value < Register) then
         -- overflow
      else
         Register := New_Value;
      end if;

   For subtraction:

      Register := ...

      New_Value := Register - delta;

      if (New_Value > Register) then
         -- underflow
      else
         Register := New_Value;
      end if;

   For multiplication:

      Register := ...

      New_Value := Register * delta;

      if (New_Value < Register) then
         -- overflow
       else
         Register := New_Value;
      end if;

   For division:

      Register := ...

      New_Value := Register / delta;

      if (New_Value > Register) then
         -- underflow
       else
         Register := New_Value;
      end if;

I know this isn't ideal, but it seems like it should work.


Another option might be (assuming a 32 bit register):

   type Bit_Array is array (1..32) of boolean;
   pragma Pack(Bit_Array);

   Register_Bits : Bit_Array;
   for Register_Bits use Register'address;

   High_Order_Bit_Set := Register_Bits(32);

   -- After addition and multiplication

   -- If the high order bit was set and is now clear
   if High_Order_Bit_Set and then not Register_Bits(32) then
      -- overflow
   end if;

   -- After subtraction and division

   -- If the high order bit was clear and is now set
   if not High_Order_Bit_Set and then Register_Bits(32) then
      -- underflow
   end if;

Or, something like that.  It's late and I'm not thinking too
clearly.

Frank

PS.
If someone else has already suggested this, and you know
of problems, then by all means disregard it.

-----Original Message-----
From: chris.danx [mailto:chris.danx@ntlworld.com]
Sent: Wednesday, March 28, 2001 5:24 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: RISC 


mod types have made some parts of the machine simple but are making
arithmetic operations a nightmare.

I need to support 2s compliment integers (floats will not feature at all)
hence mod types.  Taking not of X and add 1, then it's negative.  no probs!
Problem is with sign and overflow on add, sub, mul, div.

Each one must cope with signed nums and unsigned ones -- signal a carry or
overflow.  I think you can just do add/sub and no worries.  Problems arise
when i detect overflow, i tried thinking this out, and Martin Dowie pointed
out a possible solution that might work but only for unsigned nums.  I don't
know how to go about this signed ones.

I really need to know how to detect overflow for multiplication and
division.  I also need a way to detect it for add and sub.  Maybe Ada has an
attribute for this or something,

    e.g. ...
            type X is mod 256;
            ...
            a :    x := 128;
            a := x + x;
            ...
            if a'overflow then
                ...
            end if;

{i doubt it though!}

Can anyone help,


Thanks,
Chris Campbell

"Martin Dowie" <martin.dowie@gecm.com> wrote in message
news:3ab5d2a4$1@pull.gecm.com...
> I had a similar problem recently when I had to mimic unsigned 64 bits with
> only
> unsigned 32 bits available.
>
> For addition and subtract it is fairly easy. e.g.
>
> a = 255, b = 1
> c = a + b
> if c < a then overflow as it has wrapped
>
> similarly for subtraction with > instead of <.
>
> I only required +/- support, so I'm afraid I have no solutions for * or /
> :-(
>
> The long-hand way for multiplications would be to add e.g.
> a = 90, b = 3
> c = 0
> for I in 1 .. b loop
>   c = c + a
>   if c < a then overflow as it has wrapped
> end loop
>
> not very efficient...
>
> Sorry, no ideas spring to mind for division...
>
> chris.danx <chris.danx@ntlworld.com> wrote in message
> news:qrws6.3335$bL.360000@news6-win.server.ntlworld.com...
> > Two quickies! I hope!
> >
> >[snip]
> >
> > I'm using mod types to simulate registers in the RISC machine.  I'm
about
> to
> > implement arithmetic operations but i've thought of a problem.  How do i
> > detect overflow?
> >
> > e.g.
> >     say it was 1 byte reg
> >
> >     25*158 is too big.
> >
> >     12+254 is too big also.
>
>
>


_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada




^ permalink raw reply	[flat|nested] 82+ messages in thread
* RE: RISC
@ 2001-03-29 17:52 Beard, Frank
  0 siblings, 0 replies; 82+ messages in thread
From: Beard, Frank @ 2001-03-29 17:52 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

Probably, I couldn't think of how division could cause it because
a remainder of less than one should become zero.  But it was late
and I figured someone else would check me on it.

Thanks
Frank

-----Original Message-----

Not sure about that division - wouldn't New_Value simple become 0?

Beard, Frank <beardf@spawar.navy.mil> wrote in message
news:mailman.985835690.10322.comp.lang.ada@ada.eu.org...
> Chris,
>
[snip]
>
>    For division:
>
>       Register := ...
>
>       New_Value := Register / delta;
>
>       if (New_Value > Register) then
>          -- underflow
>        else
>          Register := New_Value;
>       end if;



_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada




^ permalink raw reply	[flat|nested] 82+ messages in thread
* Re: RISC
@ 2001-03-30 17:31 Kent Paul Dolan
  0 siblings, 0 replies; 82+ messages in thread
From: Kent Paul Dolan @ 2001-03-30 17:31 UTC (permalink / raw)


References=<9kws6.218$94.1074@www.newsranger.com>

Ted Dennison said:

=> ASN.1 had a lot of this type of stuff. Take the standard
=> "length octet" for instance (...please!). Bit 8 selects
=> between "short form" and "long form". In "short form" the
=> other 7 bits indicate the length of the contents. In "long
=> form", the other 7 bits indicate how many of the following
=> bytes are used to determinte the length of the rest of the
=> contents. (Remember, no problem can't be solved by another
=> level of indirection...) However, if bit 8 is on and the
=> rest of the bits are off, then it indicates that we are
=> using "indefinite form", where two terminator octets at the
=> end of the contents determine the length.

=> A week of wrestling with this kind of stuff several years
=> ago was enough to convince me that there are always going
=> to be some formats that just cannot be nicely handled at a
=> high-level with something like a rep clause.

Don't put ASN.1 too far in the past.  As of Q1 1998, at
least, it was alive and well as the data format for SNMP,
version 1, and as well as it worked, I can't imagine it
being easily replaced.

The other way of looking at this issue is probably that if
ASN.1 (and BER, _its_ underlying standard) were directly
supported as data type families in a compiled language,
the questions of worrying how to deal with stream oriented
data, or of fighting with representations, would go away.
In ASN.1 and BER, those are solved problems, so long as you
put each at both ends of the transaction.

The folks who designed ASN.1 took on a very hard problem:
how do you standardize the representation of dynamically
bounded amounts of indefinite precision data, and frankly,
strange as the mechanisms seem at first encounter, they are
quite elegant once the cultural shock has worn away.

Elegant and easy to implement are not synonyms.

The horror of knowing that you are going to be doing
_everything_ at the bit level has been adequately expressed
in another posting in this thread.  I ran into identical
issues in 1983, tasked with providing a library (in C for
the IBM big box of the day, I misremember which) to let
other programmers translate UDAF (Uniform Data Access
Format, I think) Honeywell 36 bit data to formats suitable
for storage on IBM 32/64 bit format media.  The answer that
worked to translate 20,000 2400' data tapes was to do it
all one bit at a time, with certain cheesy optimizations
where possible.

Cheers!

xanthian.
--
Kent Paul Dolan <xanthian@well.com>


-- 
Posted from smtp.well.com [208.178.101.27] 
via Mailgate.ORG Server - http://www.Mailgate.ORG



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

end of thread, other threads:[~2001-03-30 17:31 UTC | newest]

Thread overview: 82+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-14 20:23 RISC chris.danx
2001-03-14 21:57 ` RISC Tucker Taft
2001-03-14 22:36   ` RISC chris.danx
2001-03-14 23:03     ` RISC Fraser Wilson
2001-03-15  1:30       ` RISC Corey Ashford
2001-03-15  9:19       ` RISC chris.danx
2001-03-15 12:37 ` RISC chris.danx
2001-03-15 13:03   ` RISC Tarjei T. Jensen
2001-03-15 18:29     ` RISC Robert A Duff
2001-03-15 14:40   ` RISC Ted Dennison
2001-03-15 14:49     ` RISC Robert A Duff
2001-03-15 17:37       ` RISC Marin David Condic
2001-03-15 18:28         ` RISC Robert A Duff
2001-03-15 19:16           ` RISC Marin David Condic
2001-03-16  8:44             ` RISC Martin Dowie
2001-03-16 14:40               ` RISC Marin David Condic
2001-03-20 10:17                 ` RISC Martin Dowie
2001-03-20 14:34                   ` RISC Marin David Condic
2001-03-20 15:45                     ` RISC Ted Dennison
2001-03-20 16:39                       ` RISC Robert A Duff
2001-03-20 18:10                       ` RISC Martin Dowie
2001-03-20 18:56                         ` RISC Ted Dennison
2001-03-22  9:16                       ` RISC - largish (code listed) Martin Dowie
2001-03-22  9:34                         ` Martin Dowie
2001-03-20 18:09                     ` RISC Martin Dowie
2001-03-20 20:00                       ` RISC Marin David Condic
2001-03-20 22:30                         ` RISC Robert A Duff
2001-03-20 22:48                           ` RISC Ted Dennison
2001-03-20 23:10                           ` RISC Marin David Condic
2001-03-21  0:18                             ` RISC Robert A Duff
2001-03-21 14:31                               ` RISC Marin David Condic
2001-03-21 16:47                                 ` RISC Ted Dennison
2001-03-21 17:36                                   ` RISC Marin David Condic
2001-03-16 15:09             ` RISC Tucker Taft
2001-03-16 17:10               ` RISC Robert A Duff
2001-03-16 19:02                 ` RISC Marin David Condic
2001-03-16 20:58                   ` RISC Robert A Duff
2001-03-19 16:17                     ` RISC Marin David Condic
2001-03-19 16:45                       ` RISC Florian Weimer
2001-03-19 17:14                         ` RISC Marin David Condic
2001-03-19 17:33                           ` RISC Florian Weimer
2001-03-21  5:57                           ` RISC Lao Xiao Hai
2001-03-16 22:19                   ` RISC Ted Dennison
2001-03-16 19:13                 ` RISC Laurent Guerby
2001-03-16 20:30                   ` RISC Robert A Duff
2001-03-16 20:51                 ` RISC Ole-Hjalmar Kristensen
2001-03-16 18:33               ` RISC Marin David Condic
2001-03-16 20:45                 ` RISC Robert A Duff
2001-03-17  1:13                   ` RISC Randy Brukardt
2001-03-19 16:34                   ` RISC Marin David Condic
2001-03-19 17:49                     ` RISC Robert A Duff
2001-03-16 20:08 ` RISC chris.danx
2001-03-16 20:31   ` RISC Marin David Condic
2001-03-17 21:51     ` RISC Robert A Duff
2001-03-18  6:37       ` RISC Charles Hixson
2001-03-19 15:42         ` RISC Robert A Duff
2001-03-19 17:02         ` RISC Marin David Condic
2001-03-19 17:45           ` RISC Robert A Duff
2001-03-19 18:48             ` RISC Marin David Condic
2001-03-19 16:45       ` RISC Marin David Condic
2001-03-16 22:27 ` RISC chris.danx
2001-03-17  2:49   ` RISC Jeffrey Carter
2001-03-19  9:43   ` RISC Martin Dowie
2001-03-19 11:06     ` RISC chris.danx
2001-03-28 22:24     ` RISC chris.danx
2001-03-29  0:52       ` RISC Corey Ashford
2001-03-29 12:42       ` RISC John English
2001-03-22 20:11 ` RISC chris.danx
2001-03-22 20:51   ` RISC Marin David Condic
2001-03-22 21:02   ` RISC tmoran
2001-03-22 21:18     ` RISC chris.danx
2001-03-22 21:45   ` RISC Britt Snodgrass
2001-03-22 22:43     ` RISC chris.danx
2001-03-28 11:37   ` RISC chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2001-03-16 23:25 RISC Beard, Frank
2001-03-17 11:39 ` RISC chris.danx
2001-03-29  3:12 RISC Beard, Frank
2001-03-29  7:28 ` RISC Martin Dowie
2001-03-29 12:38 ` RISC chris.danx
2001-03-29 19:07 ` RISC Chad R. Meiners
2001-03-29 17:52 RISC Beard, Frank
2001-03-30 17:31 RISC Kent Paul Dolan

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