[net.lang] consistent bit addressing in the 68020

gnu@sun.uucp (John Gilmore) (08/23/84)

The 68000 addressed bits the wrong way (low order bit == bit 0, but
high order byte == byte 0).  This was reportedly fought over internally
at Motorola and the people who said "Let's make  BTST #0  test the data
from pin D0" won out -- they didn't want to confuse hardware types.

Well, all us software types beat on them mercilessly, so they fixed it
for the 68020.  However, they had to keep the old instructions for
backward compatability.  So they defined eight new instructions, which
all operate in a consistent way on bit FIELDS (not just bits).  You
provide a byte address, a bit number, and a bit width.  The bit number
is a signed 32-bit number; the width is 1 thru 32.  They can be
immediate fields or in data registers.  The instructions will figure
out which byte or bytes the relevant bits are in, get them, and process
them.  The 8 things you can do with them are:

	Clear them		\
	Set them		 | Same as old 68000 instructions
	Invert them		 |
	Test them		/
	Zero-extend and put them in a register
	Sign-extend and put them in a register
	Take low-order bits from a register and put them in the bitfield
	Find the leftmost 1-bit in the field, put its bit# in a register

This is especially neat for bitmapped graphics, since you can address
the screen with bit numbers on random bit boundaries and the CPU will take
care of finding and lining up the data.

jeff@gatech.UUCP (08/27/84)

The next thing you know they will number their bits from 1 to 32 like Pr1me.
				(8-{)  (my that's complicated)

Jeff Lee
CSNet:	Jeff @ GATech		ARPA:	Jeff.GATech @ CSNet-Relay
uucp:	...!{akgua,allegra,rlgvax,sb1,unmvax,ulysses,ut-sally}!gatech!jeff
-- 
Jeff Lee
CSNet:	Jeff @ GATech		ARPA:	Jeff.GATech @ CSNet-Relay
uucp:	...!{akgua,allegra,rlgvax,sb1,unmvax,ulysses,ut-sally}!gatech!jeff

steveg@hammer.UUCP (Steve Glaser) (08/28/84)

Actually, the 68020 does number the bits both ways.

Quoting from the 68020 User's Manual page 2-4:

	A bit datum is specified by a base address that selects one
	byte in memory and a bit number that selects the one bit in
	this byte.  The most significant bit of the byte is number
	seven.

	A bit field datum is specified by a base address that selects
	one byte in memory, a bit field offset that indicates the
	leftmost (base) bit of the bit field in relation to the most
	significant bit of the base byte and a bit field width that
	determines how many bits to the right of the base bit are in
	the bit field.  The most significant bit of the base byte is
	bit offset 0, the least significant bit of the base byte is
	offset 7, and the least significant bit of the previous byte
	in memory is offset -1.  Bit field offsets may have values in
	the range of -2^31 to 2^31-1 and bit field widths may range
	between 1 and 32.

Given the high-endian nature of the 68k, it makes sense to do bit
fields this way.  It also makes sense to number the bits in a word
using the natural mathematical rules (bit n is the 2^n bit in an
unsigned int).  The 68000 doesn't have the bit field data type
so it doesn't have this inconsistency.  Oh well, it could be worse.

	Steve Glaser
	tektronix!steveg