Extending sign bits. By Lee Davison.

Introduction.

Sometimes you end up with a signed value that is not in a multiple of 8 bits, the problem then is to extend the sign to fill the most significant byte.

The code.

For example, a signed value is in bits 4 to 0 of the Accumulator and is to be extended to to fill all eight ..


	AND	#$1F		; clear any unused bits	
	CLC			; clear the carry for an add
	ADC	#$F0		; set top bits clear if -ve, set if +ve		
	EOR	#$F0		; toggle bits to the correct state

Using a suitable mask, if needed, and add value this works to extend the sign for any bit in the byte.


Last page update: 23rd April, 2006. e-mail me