Re: A86: Negative numbers, sign bits, and the sign flag.


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

Re: A86: Negative numbers, sign bits, and the sign flag.





> 
>  	I have read that a negative byte is represented by counting down from 
>  255.  So -1 would be 254, -2 would be 253, etc.  But how do you know if 
>  %11111101 represents 253 or -2?  I have also read that bit 7 of a byte is 
>  called the sign bit and can be used to determine if a number is positive 
or 
>  negative, but this does not make sense to me since %11111110 is 254 which 
is 
> 
>  a positive number even though the sign bit is set. (Unless you interpret 
it 
>  as -1 which goes back to my first question.)  And also, when and how is 
the 
>  sign flag affected and how can you check it?  Thanks for your help.
>  
ok -1 is represented as 11111111 and 1 is 1
so -1 +1=0
11111111+00000001=1000000000
9 bits in the answer but the registers only hold the 8 bits on the right 
which are all zero
which is what we want
the processer never sees a number as + or - just as bits on and off but it 
can only hold 8 bits so it gets the right answer anyways 
now for the sign flag
lets say i do this

ld a,5
ld b,(somevar)
then 
cp b 	;if a-b=zero then the zero flag is set
jp z,a_equals_b
	;if a-b<0
	;then b is bigger and the carry flag is set
jp c,b_is_bigger 
jp a_is_bigger		;no other choices

check out dux's page
get the addy from acz.org