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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,78b2880bc7e78e39 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-29 04:47:12 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!news.iac.net!news-out.cwix.com!newsfeed.cwix.com!sunqbc.risq.qc.ca!news1.ebone.net!news.ebone.net!news.tele.dk!195.224.53.60!nntp.news.xara.net!xara.net!gxn.net!news5-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!not-for-mail From: "chris.danx" Newsgroups: comp.lang.ada References: Subject: Re: RISC X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: <51Gw6.503$u93.80584@news6-win.server.ntlworld.com> Date: Thu, 29 Mar 2001 13:38:34 +0100 NNTP-Posting-Host: 62.253.15.175 X-Complaints-To: abuse@ntlworld.com X-Trace: news6-win.server.ntlworld.com 985869505 62.253.15.175 (Thu, 29 Mar 2001 13:38:25 BST) NNTP-Posting-Date: Thu, 29 Mar 2001 13:38:25 BST Organization: ntlworld News Service Xref: supernews.google.com comp.lang.ada:6202 Date: 2001-03-29T13:38:34+01:00 List-Id: Thanks for the suggestions guys, I think these would work, i'm going to try them out. I had thought about this for addition c = a + b if c >= Lim then overflow a + b >= Lim a >= Lim - b -- that'd be overflow; b >= Lim - a -- this too; but i wasn't sure if i'd need to detect both cases. I'll try your suggestions and see what happens. Thanks again, Chris Campbell "Beard, Frank" wrote in message news:mailman.985835690.10322.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" 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 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 >