[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 6502 illegal opcodes questions



In article <bruce#fanboy.net-53E793.06540727052006@news.newsreader.com>,
Bruce Tomlin  <bruce#fanboy.net@127.0.0.1> wrote:

> In article <e598co$12ur$1@merope.saaf.se>,
>  pausch@saaf.se (Paul Schlyter) wrote:
> 
>> In article <bruce#fanboy.net-7FEFE6.22195226052006@news.newsreader.com>,
>> Bruce Tomlin  <bruce#fanboy.net@127.0.0.1> wrote:
>> 
>>> In article <e56rj1$7lo$1@merope.saaf.se>,
>>>  pausch@saaf.se (Paul Schlyter) wrote:
>>> 
>>>> numbers for your number crunching stuff?  Forget about Java then....  or
>>>> does your hardware have 1-complement signed integers?  Java requires
>>>> integers to be 2-complement, i.e. you must then have some emulation layer
>>>> on top of your native integer format - that's inefficient.
>>> 
>>> Seriously, has anyone used 1's complement arithmetic in the past 10-20 
>>> years or so?  And why?
>> 
>> I used a CDC Cyber-720 twenty years ago: it has 60-bit word size,
>> non-IEEE floating-point format, and one-complement arithmetic - not
>> only for integer data but for floating-point data as well!  A few
>> years later that machine was put out of service though.
> 
> Exactly.  Put out of service.  That's why I gave a range, because I know 
> how some places can be about their expensive old mainframes and micros.
> 
> And you didn't answer my other question of WHY?

Because I was hired to do it..... but then I quit that job and instead became
a consultant in the microcomputer business.  And since then I've never seen
(OK, I've seen it, but not worked with it) hardware with either 1-complement
arithmetic or byte size different from 8 bits.

> What advantage does 1's complement math have that would make someone _want_
> to use it now?

One advantage is that negation is simpler: just flip all bits.  But that's
not reason enough of course.  However, another reason could be that negating
a 1-complement number can never ever cause an overflow.  Negating a
signed-magnitude number cannot cause an overflow either (one flips just
the sign bit).

However, negating a 2-complement number can cause an overflow.  Consider a
16-bit 2-complement integer with the value -32768.  Negating that yields
+32768, however the largest possible 16-bit 2-complement integer is just
+32767.

In C, overflows are silent, so negating the smallest possible negative
value will just yield the value itself.  C++ inherited this property of C,
and so did Java - this Java program compiles even without any warning:
---------------------------------------------
class test
{
    static public void main( String args[] )
    {
        int i = -2147483648, j = -i;
        System.out.println( i + " " + j );
    }
}
---------------------------------------------

and produces this output:

-2147483648 -2147483648

which is clearly erroneous.


This wouldn't happen in 1-complement arithmetic instead there

        int i = -2147483648

would overflow directly (assuming 32-bit arithmetic)


>> Btw one could also ask:
>> 
>> "Seriously, has anyone used the Apple II, or some other obsolete 8-bit
>> micro, in the past 10-20 years?  If so, why?"
>> 
>> ...and the surprising (to some) answer is: yes!
> 
> Apples and oranges.  I'm talking about a way of doing math, and you're 
> trying to bring up a specific hardware platform.  Old platforms are 
> going to be obsolete, period.  Old math isn't necessarily so.  "That 
> calculus stuff is over 200 years old, nobody uses it any more."

Binary number representation isn't mathematics, it's numerics....  :-)

-- 
----------------------------------------------------------------
Paul Schlyter,  Grev Turegatan 40,  SE-114 38 Stockholm,  SWEDEN
e-mail:  pausch at stockholm dot bostream dot se
WWW:     http://stjarnhimlen.se/