This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

In 6502 asm, how big is a "word"?


by on (#78287)
In the manual for this, snarfblam wrote:
snarfblASM works with two kinds of values: 8-bit values (byte) and 16-bit values (referred to as “word”, though, technically, the word size for 6502 is 8-bit).


I would love to know where the above information came from, re: "the word size for 6502 is 8-bit". Nonsense.

by on (#78288)
koitsu wrote:
I would love to know where the above information came from, re: "the word size for 6502 is 8-bit". Nonsense.

It may have come from the same source as this Wikipedia article, which has this row in a table:
Code:
Year | Architecture  | Word Size |  Int Sizes   | FP Sizes | Instruction | Address Res | Char Size
1975 | MOS Tech 6502 |   8 bit   | 1 w, 2 digit |   N/A    |  1, 2, 3 w  |   1 word    |   8 bit

The data word (size of the accumulator and index registers) is 8-bit. The 2A03 loses the "2 digit" word compared to the MOS Technology part.

by on (#78313)
tepples wrote:
koitsu wrote:
I would love to know where the above information came from, re: "the word size for 6502 is 8-bit". Nonsense.

It may have come from the same source as this Wikipedia article, which has this row in a table:
Code:
Year | Architecture  | Word Size |  Int Sizes   | FP Sizes | Instruction | Address Res | Char Size
1975 | MOS Tech 6502 |   8 bit   | 1 w, 2 digit |   N/A    |  1, 2, 3 w  |   1 word    |   8 bit

The data word (size of the accumulator and index registers) is 8-bit. The 2A03 loses the "2 digit" word compared to the MOS Technology part.


Still nonsense.

EDIT: I'll explain what I mean by nonsense: a word on the 6502 is 16-bits. Period. Just because the accumulator and index registers are all 8-bit doesn't mean the 6502 term "word" means 8-bit. It doesn't. The Wikipedia article declares "Word Size" to refer to "Word Size of Architecture", which means absolutely jack squat. It's like saying "snake size".

Hey, do you know what the size of a snake is on the 6502? It's 84.5200192 bits long. Because, you know, snakes. Do you refer to the PC on the 6502 as being "two 8-bit words", or even "two 8-bit bytes?" Nobody does. It's referred to as "a word", or "16-bit word", or "16 bits".

Someone is trying to change what the term "word" means when it's 100% contextual based on processor. That entire Wikipedia page should be nuked from the face of the planet. Silly!

by on (#78314)
If you know of a good reason why "size of a machine word" should not mean "size of the accumulator", I encourage you to explain exactly why on the article's talk page so that I can help you correct the article.

by on (#78318)
tepples wrote:
If you know of a good reason why "size of a machine word" should not mean "size of the accumulator", I encourage you to explain exactly why on the article's talk page so that I can help you correct the article.


The 6502 has a "word size" of 8 because it cannot operate on entities bigger than 8 bits. In that sense "word size" is more reflective of the data bus width at the chip interface. I agree the term "word size" is confusing/misleading/etc. It's "address space" is 16-bit, not its "word size".

And, if you look at diagrams [here I mean those found in hardware manual, etc.] of the 6502 the PC is indeed shown as two 8-bit constructs glued together. In fact, almost all documentation I've seen on the 6502 treats them uniquely... PCH versus PCL.

by on (#78323)
A while ago when I first heard of this "word size" thing I thought it was nonsense, I thought that a word was always 2 bytes no matter what, but now I think it actually makes sense. It appears that "word" is not a fixed-size entity like "byte" is. The 6502 can manipulate at most 8 bits at a time, the only 16-bit values it deals with natively are addresses, not words (but even then, they're still handled as 2 8-bit numbers internally). Personally, I don't object to saying that the word size of a 6502 is 8 bits.

by on (#78324)
The instruction word size for a microprocessor is the size it uses (internally) for a decoded opcode. It is not the register size and it is not the address bus width. The word size has no impact whatsoever on a programmer and that might be why it means "jack squat" to some.

In the case of a 6502 it is a pretty obvious fact that the word size is 8 bits. An architecture's word size must not be confused with the programming term "word", which does have an impact on programmers, and for legacy reasons has come to refer to a 16-bit word.

The OP was simply explaining that he decided to stick to this same convention despite the fact that the 6502 has an 8-bit word size, which makes perfect sense.

by on (#78329)
Nessie wrote:
In the case of a 6502 it is a pretty obvious fact that the word size is 8 bits. An architecture's word size must not be confused with the programming term "word", which does have an impact on programmers, and for legacy reasons has come to refer to a 16-bit word.


This is exactly how I saw it. A "word" always refers to 16-bits, but a processor's "word size" refers to the accumulator size, which varies.

Though, what makes the 6502 an "8-bit" processor? Is it because the size of its data bus is 8 bits?

by on (#78332)
The "bit size" of a processor is about as relevant as it's clock speed. It is touted when convenient, inflated when lacking and generally meaningless.

For instance, if we say that the 6502 is an 8-bit CPU because it's data bus is 8 bits long, then so must we say the 65C816 is an 8-bit CPU. It also has an 8-bit data bus (in that there are 8 wires running out of the die to the memory chip), but it uses (up to) 16-bit wide registers. Because it uses 16-bit registers we call it 16-bit.

But then you have the Motorola 68000 series. It has an 8-bit data bus and 8-bit registers, yet supports 16-bit operations on groups of registers. Why do we not call it 16-bit?

And what about the VR4300 (CPU in the N64)? Although it was based on a 64-bit MIPS architecture it's data bus was cut to 32-bit, but still supported 64-bit operations in a similar manor to the Motorola 68000. Yet it was called 64-bit.

Bottom line is, it don't matter. A word is 16 bits. Deal :lol:

by on (#78333)
Drag wrote:
Though, what makes the 6502 an "8-bit" processor? Is it because the size of its data bus is 8 bits?


Because of the accumulator and register size, I thought. The data bus of the 65C816 is 8-bits, but it's definitely a 16-bit processor. And "instruction word" on the PIC16 are 12 or 14 bits wide, yet it's an 8-bit processor (it's harvard architecture though, meaning the program memory is separate from the data memory).

I'm not as familiar with Z80, but I know it as some kind of 16-bit operations.

by on (#78335)
ALU is what should define the bitness... ? 68K would be a 32bit CPU if it weren't for the 16bit ALU. Databus etc. are irrelevant, Pentium has 64bit databus yet its 32bit, 386SX is 32bit but has only 16bit databus.
I need to go to sleep...

by on (#78362)
qbradq wrote:
Bottom line is, it don't matter. A word is 16 bits. Deal :lol:


Generally I agree, but I would say: on the 6502, a word is 16 bits. Meaning: "the term 'word' refers to something that's 16 bits in size".

That's my entire point: it's utter nonsense to use the word "word" to describe common register sizes on a CPU. As such, that Wikipedia page should die in a fire. It's purely a terminology thing, absolutely, but anyone who has written assembly on a multitude of architectures knows exactly what "word" means with regards to that architecture. That's why I preceded my statement in my above paragraph with "on the 6502...."

Yes, I'm quite aware that non-6502 architectures may use the term "word" to describe a varying number of bits (16/32/64) depending on what operational mode it's in (think protected mode or x64). But usually assembly programmers say "word" to mean 16 bits, "dword" to represent 32-bit, and "qword" to represent 64-bit. Hey look, some other bastard knows this too. And anyone familiar with this god-awful architecture knows that if another engineer says "yeah blah blah, it's going to be a word, blah blah" and isn't precise in what he/she says, the response will always be "wait, when you say 'word' what exact size are you talking about here?" followed by a discussion that's reminiscent of Of course, this guy beautifully contradicts himself ("I use word to refer to 32-bits", then in his own assembly code uses DWORD because per Intel's architecture HE HAS TO. Derpdederp alert).

So to recap: the term "word" on 6502 refers to 16 bits. But it may not matter much since we're all dead this weekend.

I guess we could have a big discussion about what "byte" actually means too, since on some (ancient) architectures (PDP) a byte is 6 or 7 bits. And hey, did you know that in some PIC compilers "int" is 16 bits? Yeah, that makes for lots of fun, believe me. *grunts*

Werd (word).

by on (#78364)
koitsu wrote:
if another engineer says "yeah blah blah, it's going to be a word, blah blah" and isn't precise in what he/she says, the response will always be "wait, when you say 'word' what exact size are you talking about here?" followed by a discussion that's reminiscent of


Oh goodness if I had a penny for every time I've heard or had that conversation... :roll:

My bags are packed for 5/21. Are yours? :shock:

Quote:
Critics point out that this isn't the first time Mr Camping has predicted the second coming. On 6 September 1994, hundreds of his listeners gathered at an auditorium in Alameda looking forward to Christ's return.

"At that time there was a lot of the Bible I had not really researched very carefully," he said last week. "But now, we've had the chance to do just an enormous amount of additional study and God has given us outstanding proofs that it really is going to happen."

Mr Camping's argument has convinced Adam Larsen, 32, from Kansas.


Hahaha.. "this isn't the first time". "had not really researched". "outstanding proofs"?

I'm going to call every Adam Larsen I can find in Kansas on the 22nd and ask how their night was.

This thread is begging for splits! :(

by on (#78365)
That's why C has provided types of standard sizes, such as "int16_t", for over a decade now, and C++ compilers also provide them as a fairly common extension. Likewise, common SQL implementations define TINYINT (8 bits), SMALLINT (16 bits), INTEGER (32 bits), and BIGINT (64 bits) to avoid the confusing "word".

Does MOS Technology's 6502 data sheet give official names for 8- and 16-bit data types?

by on (#78370)
I have to agree that 6502 words are 8-bit. It has nothing to do with the ALU, nor holding an address; a word is technically not tied to any specific number of bits, it's a generic type that for most processors will be the external data bus and/or instruction width. Memory devices are frequently expressed as n x n-bit words where the width isn't even necessarily a power of 2. Early DRAM came in 1-bit words, so it would take 8 words in parallel to form a sufficient data bus for the 6502. Ancient mini computers may have like 50-bit words, but perhaps only 32-bit can be used for data leaving 18-bits for dedicated instruction encoding. This scheme far predates the 8086 but also fits the 8086 which has a 16-bit bus; reading a DWORD or double word thus denotes two 16-bit memory fetches. (Despite the 8088 having an 8-bit bus, the programming model is identical so they kept the notation.)

by on (#78371)
Thanks for the split. We high-jacked that poor guy's thread :D

by on (#78378)
According to the apparently and officially endorsed book on programming the 6502,65C02,65802 and the 65816.

On page 13 the term "word" is not applied to 6502. You have a 8 bit byte for data items.

For 65802 and 65816, the term double byte is used in that book.

It also describes what word means in that PDF book.

by on (#78380)
I like the nomenclature in ca65: byte and addr.

by on (#78381)
If the 6502 WORD is 8-bit (lol), what's 16-bit called on it?

by on (#78384)
qbradq wrote:
Thanks for the split. We high-jacked that poor guy's thread :D

Much appreciated. I was loathe to participate in the discussion while it was derailing my topic.

Is this a chicken or egg issue? I sort of figured that the term "word" originally came from the "native" data size (however you choose to interpret that) of a processor, and the idea of a 16-bit word just sort of cemented when "WORD" was used in 16-bit APIs and libraries and stuck around into the 32-bit era for compatibility reasons. In particular, I'm thinking of WORD and DWORD in regards to the Windows API, but I wouldn't be surprised to see this situation elsewhere.

I could be completely wrong. Either way, I'll gladly remove that text from my site if it prevents a brain aneurysm. The only reason I even thought to write that is because I've heard people complain about referring to a two-byte value as a word on 8-bit architecture. Damned if I do, damned if I don't, I guess.

by on (#78388)
3gengames wrote:
If the 6502 WORD is 8-bit (lol), what's 16-bit called on it?

The PDF that Gil-Galad linked seems to use the terms "byte" and "double byte".

To me, a "word" is the shortest free utterance in a spoken or written language. That way, the comments of text decompression code can use the term "words" with no confusion. What you're thinking of I might call an "8-bit integer", "16-bit integer", or "pointer" in a 6502 program.

by on (#78398)
tepples wrote:
To me, a "word" is the shortest free utterance in a spoken or written language. That way, the comments of text decompression code can use the term "words" with no confusion. What you're thinking of I might call an "8-bit integer", "16-bit integer", or "pointer" in a 6502 program.


I prefer speaking in clicks.

Seriously though byte, word, they're both "useless" in reality. Both are insanely and irreversibly overloaded by the treads of progress.

I use the word "octet" to unambiguously represent an accumulation of 8 "bits" of information. Though it is hard to say "double octet" or "quadruple octet" with a straight face [my oh my...octuple octet???]. For bigger than "octet" I usually revert to number-names "the 16-bits at address n". Of course, then there's the "well is the thing you're addressing *byte addressable* or only *word addressable*" conundrum.

We're all screwed. Thank God [or maybe not?] the world's ending soon.

by on (#78416)
cpow wrote:
We're all screwed. Thank God [or maybe not?] the world's ending soon.


In japan, nothing happened. God didn't specify the time zone apparently.

But don't take my word for it. :P

by on (#78418)
I'm still alive too ^^
Or maybe I just didn't notice that I died and the life after the death is 100% the same to what we actually call "life" and you can die again and again and again...

by on (#78419)
Grumskiz wrote:
I'm still alive too ^^
Or maybe I just didn't notice that I died and the life after the death is 100% the same to what we actually call "life" and you can die again and again and again...


Ahhh you mean life is like a video game?

I'm on my third set of infinite lives. :D

by on (#78423)
Nah, what he meant is "there is no spoon". We are actually in that thing. Soon, some agents will find us! And try to make us believe that "word are 8 bits, Mr Anderson".

by on (#78424)
But in a few hours, it is claimed, some of us will get an exit, so to speak. I don't buy it (Matthew 24:36).

by on (#78429)
The Matrix is probably powered by a 6502 processor, just like the Terminator ^^

Maybe an IRQ is about to occur and we loose a BRK instruction and we are all going to suffer in glitch universe until someone presses the RESET button.

Or maybe not...

by on (#78434)
Grumskiz wrote:
The Matrix is probably powered by a 6502 processor, just like the Terminator ^^

Maybe an IRQ is about to occur and we loose a BRK instruction and we are all going to suffer in glitch universe until someone presses the RESET button.

Or maybe not...


Fetching $02 to IR...
Decoding...
Executing...
.
.
.