Re: A82: Invert Number


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

Re: A82: Invert Number



When you are using negative numbers in asm you are using 2's complement,
and if you just understand that negative numbers are easy.

When you are using 2's complement 0..127 have their normal value, but the
rest of the numbers are used for negative numbers. To find what number to
use for a negative number, xor the number with FFh and add 1, so

-1 = not(00000001)+1 = 11111110+1 = FFh
-128 = not(10000000)+1 = 01111111+1 = 128

So that could be used in your asm program, but on the Z80 it is much
simpler since it has a special instruction for this. Tthe instruction
NEG will load A with 0-A, which is what you need. 

As you can see from the above there is not sign bit you just change as
long as you are using 2's complement. This is also explained in the Ash
School which i am relesing soon (hopefully).


Dines 

_______________________________________

Dines Justesen
Email: dines@post1.com or
       c958362@student.dtu.dk
WWW  : http://www.gbar.dtu.dk/~c958362/
_______________________________________

On Wed, 27 Aug 1997, Matt Maurano wrote:

> I need to get the opposite of a number. In TIbasic, you could do -X->X.
> How can I do this in Asm? If I could just xor the sign bit, that should
> do it. Now, if only I understood xor and where (if there is one) the
> sign bit would be. In case it matters, I'd be using it on an 8bit
> register, probably the a reg.
> 
> 


References: