6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 15, 2024 3:22 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: order of binary digits
PostPosted: Fri May 20, 2022 9:15 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
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?


Top
 Profile  
Reply with quote  
PostPosted: Fri May 20, 2022 9:50 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 20, 2022 9:57 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
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


Top
 Profile  
Reply with quote  
PostPosted: Fri May 20, 2022 11:47 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Ok thanks, so usually #%76543210. When might this "usually" rule of thumb break down and throw me off?


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 12:25 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8541
Location: Southern California
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?


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 5:41 am 
Offline

Joined: Fri Feb 12, 2021 10:17 pm
Posts: 34
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


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 5:50 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8489
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 8:42 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 336
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.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 11:18 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10980
Location: England
I have a feeling TI did the same, in the 9900 era. Yep, datasheeet confirms it!


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 12:28 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
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.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 3:35 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Attachment:
Capture2.PNG
Capture2.PNG [ 141.46 KiB | Viewed 1095 times ]

_________________
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)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 14, 2022 12:19 pm 
Offline
User avatar

Joined: Tue Aug 11, 2020 3:45 am
Posts: 311
Location: A magnetic field
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.

_________________
Modules | Processors | Boards | Boxes | Beep, Beep! I'm a sheep!


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 14, 2022 5:29 pm 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 279
Location: Placerville, CA
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: