order of binary digits

Building your first 6502-based project? We'll help you get started here.
Post Reply
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

order of binary digits

Post by jeffythedragonslayer »

When I see binary digits written out in 65x code, is the order #%01234567 or #%76543210? I know there isn't really a concept of bit-endianness but is the most or lead significant bit written first?
gfoot
Posts: 871
Joined: 09 Jul 2021

Re: order of binary digits

Post by gfoot »

jeffythedragonslayer wrote:
When I see binary digits written out in 65x code, is the order #%01234567 or #%76543210? I know there isn't really a concept of bit-endianness but is the most or lead significant bit written first?
Usually the most significant digit is written first, like in other number bases.
User avatar
Dr Jefyll
Posts: 3525
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: order of binary digits

Post by Dr Jefyll »

gfoot wrote:
Usually the most significant digit is written first, like in other number bases.
Yes. And the numbering of those bits is usually from right to left. That is to say, the least-significant bit (the one on the far right) is Bit 0.

-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

Re: order of binary digits

Post by jeffythedragonslayer »

Ok thanks, so usually #%76543210. When might this "usually" rule of thumb break down and throw me off?
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: order of binary digits

Post by GARTHWILSON »

There are no exceptions to this rule. Ever. What you might be thinking of is byte order (as opposed to bit order). In 16-bit quantities, 6502 puts the low byte first. This makes it more efficient in certain circumstances. See the explanation and examples at the bottom of the 6502 primer page about memory-map requirements, at http://wilsonminesco.com/6502primer/MemMapReqs.html, specifically the last five paragraphs, after the heading "Low Byte First."

Also, UARTs output bit 0 (the lsb) first. They go backwards. Bit 0 is still the lsb though. (In terminology, "lsb" in lower-case is "least significant bit," and "LSB" in capitals is "least significant byte." The same goes for msb and MSB for most significant bit and byte. Yes, case matters.)
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
noneya
Posts: 39
Joined: 12 Feb 2021
Contact:

Re: order of binary digits

Post by noneya »

As a visual example, assume you have a 6522 VIA, you have set your data direction register for output and you want to follow that up by setting pin 2 (bit 1) to a 1 (hot), and all others to zero.

To accomplish this you would write hex #$02 or %00000010 to the given via port. Looking at the pins of this via port from left to right, we would observe the following relationship whereas X indicates the pin is hot ( a one) and others are "off" ( a zero) :
hex #$02 or
%0 0 0 0 0 0 1 0 will yield a pin relationship of
_ X _ _ _ _ _ _

The reason for this is that the bits are shifted into the via. i.e. shift registers.
> %0 1 0 0 0 0 0 0 << Representation after being shifted into the VIA
^ _ X _ _ _ _ _ _
< %0 0 0 0 0 0 1 0 << Value as you would code
Shaking out the dirty bits!

https://github.com/DonaldMoran
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: order of binary digits

Post by BigDumbDinosaur »

jeffythedragonslayer wrote:
Ok thanks, so usually #%76543210. When might this "usually" rule of thumb break down and throw me off?

As Garth said, never. Bit order is an industry standard, not just confined to the 65xx world. In the case of the 65C816 running in native mode with 16-bit registers, the bit order still holds; bit 0 is on the right and bit 15 is on the left.

Also, #%76543210 would not be a valid operand. Only 0 and 1 are allowed in a bit field.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
John West
Posts: 383
Joined: 03 Sep 2002

Re: order of binary digits

Post by John West »

I don't remember ever seeing bits written with the least significant on the left and the most significant on the right, but I have seen them numbered in the opposite order. That is, the bits in an eight bit value would be numbered 01234567, where bit 7 is the least significant (the 2^0 = 1 place) and bit 0 is the most significant (2^7 = 128).

This was on PowerPC, which I believe inherited it from POWER. It was as confusing as you might expect.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: order of binary digits

Post by BigEd »

I have a feeling TI did the same, in the 9900 era. Yep, datasheeet confirms it!
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: order of binary digits

Post by BillG »

The IBM 360 is the earliest computer I know in which bit #0 is the most significant.

Except for some bit test, set and reset instructions, it is not important to know which one is considered to be bit #0.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: order of binary digits

Post by barrym95838 »

Capture2.PNG
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)
User avatar
Sheep64
In Memoriam
Posts: 311
Joined: 11 Aug 2020
Location: A magnetic field

Re: order of binary digits

Post by Sheep64 »

GARTHWILSON on Sat 21 May 2022 wrote:
There are no exceptions to this rule. Ever.
You say that as competent professional but I have a lightly contrived scenario where a newbie may go astray.

Step 1: Get 6502 executing NOPs on a breadboard. We'll ignore that they should be using 65816 and avoiding breadboards but we'll keep going.

Step 2: Wire 6502 to ROM. Get 6502 to idle loop at $FD00 and $FE00 and use address line 8 to output Morse code. This requires wiring address lines and data lines in a sane order.

Step 3: Wire ROM to RAM. This works when the address lines and data lines are in any order - intentionally or not.

Step 4: Wire RAM to 6522. This is where the fun begins. Any drafts-person will know to measure from one spot. The same principle should apply when extending a bus. Don't make the address lines or data lines match the RAM. Make them match the processor.

Step 5: Attempt to fix hardware bug in software.
User avatar
commodorejohn
Posts: 299
Joined: 21 Jan 2016
Location: Placerville, CA
Contact:

Re: order of binary digits

Post by commodorejohn »

Yeah, some computer manufacturers numbered bits with #0 as the MSB, for...reasons. Don't know what the rationale may have been, unless it was just that, well, you write the MSB first, but it's always driven me crazy as it fails the simple logical test that place value = 2 ^ bit #. TI is the only place I know of that continued it into the relative modern day, although they seem to have finally abandoned it going by the MSP430 documentation.
Post Reply