A83: Re: help with math


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

A83: Re: help with math




You can't have positive/negative 8-bit numbers with an 8-bit register.  You
have a 7-bit signed number.  Or an 8-bit unsigned number.  They are treated
almost exactly the same with most operations.  The only times that you have
to do things differently is when comparing overflows/carries and such.

It's actually quite simple.  How would you store -1?  Well, what happens
when you decrement an 8-bit value that is 0?  You get 255.  All bits set.
Numbers wrap around.  -2 would be 254, and so forth, up until you get
to -128, which would be 128 positive.  Then it "wraps" to 127.  Essentially,
the highest order bit (bit 7 for 8 bits) is the sign bit.  For positive
numbers, they count in binary going up.  For negative numbers, they count in
binary going down (starting with all the bits set).

If this doesn't make sense or seems wrong, work some numbers out on paper
(the Windows Calculator is what I always use to convert bin/dec/hex numbers)
and do some test additions/subtractions.  I don't remember if
multiplication/division works implicitly as addition/subtraction do.  I
think for them the easiest way is to set the sign by hand, depending on your
algorithm.

> (note: could someone explain this to me: i thought it
> wasn't possible to have negative integers in the
> registers but a bunch of stuff i've seen appears
> otherwise, since there also is a "neg" opcode to find
> the negative of a. How is the negative sign stored in
> a 8 bit number???)


_____________________________________________
NetZero - Defenders of the Free World
Click here for FREE Internet Access and Email
http://www.netzero.net/download/index.html



References: