## RE: [stella] some little 6502 questions (fwd)

 Subject: RE: [stella] some little 6502 questions (fwd) From: Matt Pritchard Date: Fri, 28 Mar 1997 17:48:32 -0600
```	> Is there a faster way than this to get the absolute value of
the accumulator?
>
>   (...)
>
>   BPL plus
>   EOR #\$FF
>   CLC
> plus:

>Assuming that you mean A is an 8 bit signed number (-128 to
+127), and that
>you just want to get rid of the sign, try this:

>AND	#%01111111	; this should mask off the sign bit
>			; note that abs(-128) would be 0 using
this method

Uhhhmmm! I don't think this will work.  For signed 8-bit
numbers:

-1 = %11111111
-2 = %11111110
-3 = %11111101
etc...

so   -1 AND %0111111 = 127  (incorrect!)

i.e.     %11111111 AND %01111111  = %01111111

The reason for two's complement notation is that you can do  36
+ -2 = 34   (%00100100 +  %11111110)   and it works...

Matt Pritchard
graphics_grunt@ensemble_studios

--
Archives available at http://www.biglist.com/lists/stella/archives/
E-mail UNSUBSCRIBE in the body to stella-request@xxxxxxxxxxx to be removed.

```