Monday, August 3, 2026

3809/2801: 6502 Indexed Addressing, Including Memory Indirect

2801
6502 Indexed Addressing, 
Including Memory Indirect

ALUs, Register Indirect Review, 
Role Playing the 6800

TOC

"Okay, Harvey, you said the 6502 has two index registers, but they are only eight bits wide, right?"

"That's what my notes say." 

"And, Pete, you mentioned a 16-bit index base constant part for the instruction."

"I thought it might be a possibility."

"What benefit would it have?" 

"When you know an array's address, it could start anyplace in memory, as opposed to the 6800's 8-bit constant part. But the index register would still limit the array's width." 

Mr. Mori put a transparency on the projector. 

"Something like this?" 

Mr. Mori stopped and looked at the diagram. "Oh, wait. The 6502 assembler syntax uses parentheses to mean indirection, and this is going to be confusing. Let me fix this."

He erased the punctuation in question: 

Pete said, "So I guessed right?" 

"I guess you did. What else is different about it, different from the 6800 and 9900?"

"Little endian," Harvey said.

"Yep. The 6502 puts its low byte first, like the 8080 and the 1802." 

Bill asked, "Are X and Y interchangeable?"

"Sort of. There are some differences in which instructions and addressing mode can be used with which. We'll talk about it in a minute or so, but Y indexing is not supported for some single-operand instructions. File that fact away in your brain somewhere, and we'll come back to it."

Ted raised his hand. "Single-operand instructions means read-modify-write?"

"You're trying to confuse everyone."

"Sorry."

Mr. Mori grinned. "Just kidding. You're right and we'll talk about that later, too. Probably not today." He paused, then asked, "Can anyone think of a way of getting around the width limitation?" 

I suggested, "Use the middle of the array for the constant base address?" 

Mr. Mori nodded. "Can you tell us how to do that?"

"Uhn --"

While I was thinking, Frank raised his hand.

"Frank?"

"If the array is larger than 256 bytes but smaller than 513, provide one routine to point into the low half, and provide another to point into the high half. Then you can figure out somehow which half you're needing to point to, to choose which routine to use."

"Very good, and we'll talk about how to actually do that later, as well, because knowing how can be useful. Not today, I think. And there's another way that involves modifying the constant base in the actual op-code at run-time, but I do not want to teach you that."

"Why not?" Karl asked.

Cyndy said, "You might accidentally modify the wrong part of the instruction?"

"That's part of it," Mr. Mori agreed. "What else?"

Frank said, "You might modify the constant part of the instruction once, and something might interrupt the code, modify it again, and then somehow fail to restore it before the original code finishes accessing the array, which would really confuse the code." 

"Excellent. And the guys who designed the 6502 knew that could happen, so they gave us another way that doesn't require separate routines for each 256 bytes of the array, but I want to talk about that after I talk about something else." 

He picked up another transparency. "I need to erase the parentheses on this one, too." He did so and replaced the one on the projector. "Just to be complete, what does our 16-bit constant part and 8-bit variable part mean for arrays when you don't know where an array begins until the program runs?" 

"If the base address is in the index register and the 16-bit part in the instruction is the offset, that's pretty much useless," Karl complained.

"Why so?"

"How often are you going to have an offset larger than 256 when the array starts in page zero?"

"Good point. The architects of the 6502 knew this as well, probably from programming the 6800, and they provided a short indexed mode." Mr. Mori picked up another transparency, fixed it, and swapped it in.

"So you can put the base address in the index register and only use one byte for the offset. They were saving space in the op-code table, so the Y index register can't do this except for two instructions, load X and store X. And I'm not sure whether the guys who designed the 6502 did this for some reason or it just worked out that way, but this address mode wraps around in page zero, so you'll need to remember that, too."

I asked, "So the entire array has to fit in page zero?"

"If it doesn't, you'll have to use the 16-bit offset form for the parts that go beyond, which can get really awkward, or just use the 16-bit offset form for the whole array."

Bill said, "I think I can see that." 

"Of course, we can also do 8-bit constant base with 8-bit variable index with this addressing mode, as we have discussed before. Gotta fix this one, too." He did so, and swapped another transparency in.

Karl said, "And this still limits the useful size of arrays."

(Surprisingly, there are a lot of useful applications for microcontrollers that don't actually need any more than 256 bytes for any particular array, or even for all arrays. In fact, one of Motorola's corporate customers pointed this out to Motorola sales engineers, probably about the time I and my real-life classmates were beginning the Industrial Electronics class in the real world. And Motorola would respond by designing the 6805, which would be appropriate to describe as a half of a 6801 -- almost literally. Or maybe half a 68HC11. Only the accumulator A, only an 8-bit X. Some bit handling instructions not in the 6800 or 6801. But the 6805 and its descendants would become one of Motorola's biggest cash cows in your reality. Some analysts would estimate that descendants of the 6805 outnumbered all other microprocessors and microcontrollers delivered in the early 1990s, before ARM ..., but I'm getting way ahead of the story again.)

"If we had some way to work on all 16 bits of an address in memory and then use the result as an address, it would help, right?"

Karl grunted agreement. "I don't see any way to handle generalized arrays with just what you've described, except by what you said, multiple access functions or run-time self-modifying code. Is there a 16-bit index register hidden away somewhere?"

"That brings us to two more addressing modes in the 6502 which are called memory indirect addressing modes."

Bill said, "Indirecting from memory would be like indirecting through the 9900's working registers?"

"Sort-of kind-of pretty much like, the way I see it." 

Harvey added, "So X and Y are only eight bit, but the 6502 can use 16-bit addresses directly out of memory?"

"Directly indirectly." Mr. Mori grinned at his own joke. None of us students really got why it was amusing, just yet.

"Let's look at one of these addressing modes." Mr Mori swapped transparencies. "The first one is a kind of extension of the short indexed mode, but what you are indexing in the direct page is an array of addresses that the 6502 can load into its address buffer. You might use it something like this:" 

 

"Note that we are now scanning the list of addresses, not the string, with the index register. Maybe I should have shown the address buffer in this, but that might not be exactly accurate. Hmm. Let's give it a shot." 

Karl stood up and said, "So there is a 16-bit address register hidden in there!" 

Mr. Mori reworked part of the diagram while we watched. "Yeah, sort-of. Whether it's an actual 16-bit register or not, I don't know. But it's as if there is one there." 

 

Karl sat down as Frank said, "So you with this we can look at the length byte, but how would you scan the string?"

I suggested, "You could have a 16-bit variable that's an array of one, that you can copy the address to, and do address math on that like we did on the 6800, and then use this indirect mode on the array of one?"

"Might work, but what happens to X while you're doing that?" Mr. Mori asked.

Ted said, "I think it gets walked on."

I asked, "Can you use this mode with Y so you can keep X pointing to the array?"

Mr. Mori said, "You guys are thinking. Great. Y does have a little bit different use. Let's look at it." He swapped transparencies. 

"Oh, let me put that address buffer in here." 

He started reworking one part, then stopped again for a moment. 

"Except there must be two virtual 16-bit buffers, according to the timing charts. Or they figured out a way to reuse it pretty efficiently. Hmm." 

He reworked another part, as well. 

"I'm not sure, as you may have heard me just telling myself, whether the 6502 adds Y to the same address buffer it used to bring the address out of P, or whether there are two separate buffers. No guarantees on the actual accuracy of this diagram. Either way, hopefully, you can see something of how it works in this diagram."

I said, "So P in this is like Rick's and my X16 variable --"

Rick said, "That was your X16 variable, but, I think you're right. It looks like we can do math on that in memory, and then it can be used directly as a base address with Y as the index. Which overcomes the width and location problems like in the 6800, but without having to load and store the 16-bit X."

Bill said, "So, we could load an address from a table of string addresses indirecting from X, then move that address to P and use P to scan the string." 

Harvey said, "I think you'd use the X indirection to do something like checking the length of these strings, and if the length is in the right range, use regular indexed instructions to load the pointer to P, where you could use the Y indirection to scan the strings." 

Mr. Mori said, "Harvey, do you want to try writing some code to do that?"

"Uh, not really."

Mr. Mori picked up the marker from the whiteboard tray. "How about if Bill helps?"

Bill and Harvey looked at each other doubtfully, but Bill stood, and then Harvey stood, and they went to the whiteboard. Harvey picked up the marker.

Harvey said, "Do we put the address of the array of string pointers in X?"

Bill said, "Let's use the address for the constant part, like the example shows."

Chuck asked, "Could it go either way?"

Mr. Mori said, "Let's wait to think about that."

Harvey wrote

  LDX #4    ; 3rd string is offset 4

Bill said, "We need to get the length to look at it."

Harvey hesitated, and  then wrote

 LDA (N,X) ; N array is in page 0, get length of string

"Then what?" Bill asked.

Hec said, "We don't really know how this part works."

Mr. Mori said, "Just write something."

Harvey wrote

 (something) 

Everyone laughed, but Mr. Mori said, "Good." 

Bill said, "Assuming we can proceed, we need to load the address into P.

Harvey said, "And we do that byte-by-byte." He wrote,

 LDA N,X ; low byte of address
 STA P ; P is in page 0
 LDA N+1,X ; high byte of address
 STA P+1

Karl said, "Is that legal? I can see P plus one, but N+1 --" and he trailed off. 

Chuck said, "Bumping the constant for the base by one probably has the same effect as bumping the variable X  by one, doesn't it?" 

Mr. Mori said, "It does."

"Okay," Bill said. "We need the offset into the string."

"Put it in Y?" Harvey suggested, then followed his own suggestion.

 LDY #3 ; 3rd char after length

Bill said, "I guess we're ready to do whatever it was we were going to do."

Harvey said, "That was op B, wasn't it?" and wrote,

 opb (P),Y

"Did I get the parenthesis right, Mr. Mori?"

"That's the way I understand the syntax to work. Parentheses indicate indirection." Mr. Mori replied.

Mark said, "So the 6502 is carrying the concept of page zero as a bank of pseudo-registers a bit farther than the 6800."

"Thank you for pointing that out." replied Mr. Mori. 

I said, "But we still aren't really scanning any strings. We need some way to repeat things."

"True. Anyway, once you understand how these two modes work here, I think you'll be able to think of more ways to use them." 

Karl said, "I don't really see how modifying P is significantly different from modifying the address field of an instruction. If you modify P and then something interrupts and modifies it again before you can use it, you're still going to be using a wrong base address."

Mr Mori said, "Good point. One difference is, as Cyndy pointed out, that you are less likely to overwrite actual instruction object code with P. Another is that you can collect P with other variables that need to be swapped out and restored when an interrupt happens. It makes it easier to manage what needs to be managed."

Karl set his mouth in thought. 

Mr. Mori let us think some more before continuing. "Now there's one more mode, and I want to mention it. It's a mode only for jumps, that they call absolute indirect in the docs. An absolute jump moves program flow to the 16-bit address that the instruction specifies. An absolute indirect jump moves program flow to the 16-bit address that is stored at the address specified in the instruction."

Barry said, "So, the absolute jump is like load PC immediate, and the absolute indirect jump is like load PC absolute?" 

Scott and Bob groaned, but Mr. Mori said, "That's another way of looking at it, but I'm afraid some of our students will be confused.

Mark stood up and went to the whiteboard. 

Mr. Mori said, "Looks great. There is a bug in this instruction, however. When the instruction specifies an address with a low byte of 255, it grabs the low byte of the new PC from the proper place, but then wraps the address around to get the high byte instead of incrementing."

"So we should never give it an address that ends in hexadecimal $FF, then," Mark said. He wrote in a note next to address 2101, "Don't use JMP (0XXFFH). No 255 in low byte.".  And he put the marker back and sat down.

"Correct."

Mr. Mori shut the overhead projector off, leaving it in place to cool.

"We've been burning the brain oil, so let's shift gears and look at your letters of inquiry." He moved an opaque projector in beside the transparency overhead projector.

"About your letters of inquiry, Ms. Wilson informs me that she will not allow Cyndy and Joe to type anybody's letter of inquiry for them in the school's typing lab. I must say that she has convinced me of the folly of the plan."

There were a few scattered groans and complaints, along with some "Of course." and such.

"On the other hand, she did have an another plan, and I think it's a better plan. She thinks she might be willing to hold the computer lab open after school for you guys to go over in small groups, and she can coach you and then let you type them up yourselves. But she needs to check with administration first."

Responses shifted a bit more to the positive.

"I think most of you realize that typing is a useful skill when you're working with computers. So if she gets approval, this could be a good opportunity. But you must all understand that, if you do this, you must treat the typewriter lab equipment with respect, no less respect than our electronics lab."

Mark said, "No playing football with the typewriters, Karl."

There were scattered chuckles. 

"Hey!" Karl objected. "I know how to throw a typewriter respectfully."

More chuckles. 

Mr. Mori gave us an indulgent frown. "Getting yourselves kicked out of school would leave us short of students again. Don't do that." 

There was scattered laughter.  

Rick and Hec shook their heads.

Cyndy's eyes grew wide with concern.

I gave it all an eyeroll.

"Guys," Cyndy exclaimed, "Think of what Ms. Williams would say if she heard this. She'd probably change her mind."

The jesting suddenly stopped.

Karl coughed. "Sorry, Cyn. Just kidding."

"'Cyndy', to you."

Karl ducked his head in apology. 

"The problem with jokes is when they suddenly quit being jokes," Mr. Mori's voice was sober. "There are parts on those electric typewriters that I'm sure some of you will be tempted to get your fingers into or treat like balls. I don't want to have to be this way, but I will have to have promises from everyone who goes to behave yourselves. I may even need a permission slip from your parents."

Mark said, "I guess that was partly my fault, too, leading off like that. Sorry, Karl. Sorry, guys." 

There were general murmurs of agreement, and Mr. Mori let them die down. 

"So, Joe," he shifted gears. "Do you have your letter with you?" he asked as he turned the opaque projector on.

Cyndy gave me a querying look, and responded before I could. "I have mine typed up." She slipped it out of her notebook and handed it to Mr. Mori while I got my copy from the typing class out.

He looked puzzled, and accepted Cyndy's, but turned to me. I handed him the letter I had typed at school. 

Rick glanced over at me. "You kept a copy, then. Smart move." 

Mr. Mori looked them both over, then said, "It looks like you both did a bit more editing before typing these up yesterday."

"Ms. Wilson made some suggestions," Cyndy explained before I could.

"Nice of her."

Cyndy was still querying me with her eyes. 

"We've been asked to be careful about showing students' actual addresses and phone numbers in class, do you mind if I mark out your address and phone number and show this to the class?"

"No problem, either way," I replied. "But, for the record, that's not what I actually sent."

"Sent?" Mr. Mori gave me a quick look.

"I guess I got impatient last night." 

He blinked at me. "You have a typewriter at home?"

"Dad does, but I sent it handwritten. I was careful to make it legible."

Mr. Mori looked non-plussed. "Administration wants copies of every letter sent. I don't guess you made a copy of it?"

"Scratch copy in pencil, with mark-up," I said as I turned to dig into my notebook for the scratchwork, but Cyndy was holding a piece of paper up for me.

It was my turn to to give her a querying look.

"You might want this," she said, quietly, with a knowing smile.

I blinked and accepted it. 

It was my own writing, the letter I thought I had sent the night before. 

"What? How on earth?"

Cyndy smirked and kept her voice low enough only Hec and Rick and I could hear. "She said you didn't notice."

"She --" I kept my voice low as well.

Mr. Mori watched our exchange with interest. 

"Writes fast. And accurate." 

I gave an embarrassed laugh and covered my eyes with the letter for a moment before handing it over to Mr. Mori without comment. 

"Secrets?" Mr. Mori asked. He looked at Hec, who shrugged.

"Well, good for you, you did make a copy. Does not look like pencil, though. And I don't see any mark-up."

I coughed. "I'm going to have to blame this one on my study partner."

"Good for you, Cyndy, although you might have gone so far as to encourage him to be more patient."

"Hec and I studied at my house last night." 

"Rick?"

"Different study partner," Rick said. 

Mr. Mori gave the four of us a look and said, "Curiouser and curiouser."

None of us volunteered more information.

He chuckled. "Well, let's take a look. I'll go ahead and mark out your address and phone number." 

He compared mine with Cyndy's and said, "I think I'll start with Cyndy's after all." 

He marked her address and phone number out and put her letter on the platen and adjusted the projector. "Okay, she uses standard greeting --"

"What happens," asked Harvey, "if they aren't sirs?"

"'Dear Sirs' is standard greeting. They won't be upset. Odd-ball greetings will not impress anyone."

"Oh."

"She identifies herself and our school, and our class. She gives my name as the teacher and the school address and contact information we showed you yesterday.

"Then she explains her interest in the 8080, that we will be studying it in class. It's a little bland, but that's actually good. 

"And she asks for information on how to obtain documentation for both the microprocessor and its support parts. And she closes. 

"Clean grammar, no attempts to dress things up. No particular reason to refuse the request. She will likely get some standard advertising material, a list of parts that she can request information about, and a standard order form for the datasheets." 

He looked around the class. "Any questions?" 

Nobody thought of anything immediately.

"Okay." He took Cyndy's out and gave it back to her, and replaced it with my typewritten inquiry, after marking out my address and phone number.

"We see Joe has done essentially the same here. You'd think they typed these up together yesterday in typing class." He chuckled to himself. "But you can see some differences in expression. Which do you guys think is more likely to get a good response?"

We spent a minute or two critiquing Cyndy's and my different ways of wording things.

"Okay." He gave me back my typewritten letter, then marked my phone number and address off the handwritten letter and put it on the platen. "In this version, Joe is explicit about his interest in the 6800. He isn't just interested in it for class, he thinks there are advantages. He even goes so far as to name all the microprocessors we are studying. 

"I'm not sure that's a good idea. I'm not sure it's a bad idea. It is something of a sales pitch approach, however, and we need to be aware that it may be received as insincere. It may also be received as ambitious."

"The inquiry itself, he's becoming more ambitious. In addition to information on the CPU and related parts, he's asking for information about development tools.

"Now, whoever handles this at Motorola might not think about a student wanting to know about development tools. The development tools aren't cheap, and they may wonder whether Joe understands that. I do think they are more likely to reply with some information about development tools, since he asks.

"But he does sound like a kid who's asking bigger questions than he realizes. Sorry, Joe."

I nodded. 

He continued, "On the one hand, I don't recommend Joe's approach in general. Smaller companies without secretary staff, an engineer may get the letter and tend to set the inquiry aside to respond to when he has more time to think about it. On the other, I'm not sure it would hurt with Motorola, they are a fairly large company, and it is more likely the letter will be handled entirely by a secretary. I guess we'll see." 

He took my other letter off the platen and gave it back to me. "Harvey, are you willing to let us see yours?"

"Uh, sure." He already had his out, and handed it to Mr. Mori. "No problem if you mark out the address and phone number."

Mr. Mori scanned it. "Okay, here we see some differences." He marked out the personal information and put Harvey's letter on the platen. "Harvey is sending his to Apple, which is a company selling computers, not a company selling microprocessors. Well, selling the mainboard. So what he is asking for is comprehensive information on what the mainboard includes, and what options Apple sells for it at that apocalyptic price, which, low as it is for a computer that is almost complete, is enough to buy a pretty decent used car."

He looked up. "The letter is okay, but you guys should know. The apocalyptic price does not include the TV used as an output device. It also does not include the keyboard, power supply, or a cassette interface. So there is some assembly required. And Apple is selling them so fast they really haven't had time to print up a lot of the documentation materials that they might be willing to send to students.

"I don't want to discourage you, Harvey, but you might do better just sending an inquiry to MOS Technology about their KIM-1. It doesn't output to the TV, but it's much cheaper, and you can ask about the 6502 and peripheral parts at the same time. You might want to reference Joe's letter." He handed Harvey back his letter.

"Do you mind, Joe?" Harvey asked.

"No problem." I passed my second letter over to him, and he started copying from it.

Rick said, "Harvey, can I check your letter for ideas? I'm going to be sending mine to Southwest Technical Products, to ask them about their 6800-based computers."

"Sure." Harvey passed his letter to Rick. 

Mr. Mori asked, "Anybody get a letter to RCA or TI?"

Hec said, "I've got one to send to RCA, but it basically looks like Cyndy's."

I said, "You might want to take a look at the COSMAC manual over at OC before you send it."

Hec looked thoughtful. "Maybe so." 

Mr. Mori looked at Ted, but Ted shrugged and didn't say anything.

"Well, we're close to the bell. I'll let you guys clean up your notes or work on letters of inquiry."

I went to the front of the room and looked through more magazines while Rick worked on his letter. I found an ad for the MEK6800d1 and read it before taking it back to show Rick.

Hec read a little over Rick's shoulder and then went back to the magazine stack and thumbed through more magazines, finding an article on the COSMAC ELF, which he brought back to the table. Cyndy read over Hec's shoulder. When Harvey brought my letter back and Rick gave him his back, he saw what Hec and Rick were looking at, and went up and thumbed though more magazines, finding an ad for the KIM-1.

We passed the magazines around, and Barry dug up an ad for Intel's SDK-80 in another magazine. No one was able to find ads for any similar devices for the 9900.

While we were digging around in magazines, Mr. Mori was talking with Chuck. 

After class, Mr. Mori snagged Ted to talk. Ted seemed hesitant. 

Cyndy and Hec left together, deep in discussion. Rick and I headed out, and met Sapphire outside Rick's next class, and Sapphire and I walked to the typing lab together. 

"Mom suggests that we should study where others are around."

"Oh?"

"My leaving early for your seminary seemed to worry her."

"We'll have to see what she feels comfortable with, I guess."

"But there are things I need to ask you that I won't feel comfortable about if there are other people around."

"I'm sure we can figure something out."

We stayed outside the classroom, holding hands and not saying much until Cyndy approached, and we went inside. 

 

TOC
Next
Where it starts

Copyright 2026 Joel Matthew Rees




[Edit record here:  https://joelrees-novels.blogspot.com/2026/08/mark00-3809-2801-6502-indexed-addressing-including-indirect.html]


[MARK00] 3809/2801: 6502 Indexed Addressing, Including Memory Indirect

EDIT MARK record 00
Read the current version at: 
https://joelrees-novels.blogspot.com/2026/08/3809-2801-6502-indexed-addressing-including-indirect.html

2801
6502 Indexed Addressing, 
Including Memory Indirect

ALUs, Register Indirect Review, 
Role Playing the 6800

TOC

"Okay, Harvey, you said the 6502 has two index registers, but they are only eight bits wide, right?"

"That's what my notes say." 

"And, Pete, you mentioned a 16-bit index base constant part for the instruction."

"I thought it might be a possibility."

"What benefit would it have?" 

"When you know an array's address, it could start anyplace in memory, as opposed to the 6800's 8-bit constant part. But the index register would still limit the array's width." 

Mr. Mori put a transparency on the projector. 

"Something like this?" 

Mr. Mori stopped and looked at the diagram. "Oh, wait. The 6502 assembler syntax uses parentheses to mean indirection, and this is going to be confusing. Let me fix this."

He erased the punctuation in question: 

Pete said, "So I guessed right?" 

"I guess you did. What else is different about it, different from the 6800 and 9900?"

"Little endian," Harvey said.

"Yep. The 6502 puts its low byte first, like the 8080 and the 1802." 

Bill asked, "Are X and Y interchangeable?"

"Sort of. There are some differences in which instructions and addressing mode can be used with which. We'll talk about it in a minute or so, but Y indexing is not supported for some single-operand instructions. File that fact away in your brain somewhere, and we'll come back to it."

Ted raised his hand. "Single-operand instructions means read-modify-write?"

"You're trying to confuse everyone."

"Sorry."

Mr. Mori grinned. "Just kidding. You're right and we'll talk about that later, too. Probably not today." He paused, then asked, "Can anyone think of a way of getting around the width limitation?" 

I suggested, "Use the middle of the array for the constant base address?" 

Mr. Mori nodded. "Can you tell us how to do that?"

"Uhn --"

While I was thinking, Frank raised his hand.

"Frank?"

"If the array is larger than 256 bytes but smaller than 513, provide one routine to point into the low half, and provide another to point into the high half. Then you can figure out somehow which half you're needing to point to, to choose which routine to use."

"Very good, and we'll talk about how to actually do that later, as well, because knowing how can be useful. Not today, I think. And there's another way that involves modifying the constant base in the actual op-code at run-time, but I do not want to teach you that."

"Why not?" Karl asked.

Cyndy said, "You might accidentally modify the wrong part of the instruction?"

"That's part of it," Mr. Mori agreed. "What else?"

Frank said, "You might modify the constant part of the instruction once, and something might interrupt the code, modify it again, and then somehow fail to restore it before the original code finishes accessing the array, which would really confuse the code." 

"Excellent. And the guys who designed the 6502 knew that could happen, so they gave us another way that doesn't require separate routines for each 256 bytes of the array, but I want to talk about that after I talk about something else." 

He picked up another transparency. "I need to erase the parentheses on this one, too." He did so and replaced the one on the projector. "Just to be complete, what does our 16-bit constant part and 8-bit variable part mean for arrays when you don't know where an array begins until the program runs?" 

"If the base address is in the index register and the 16-bit part in the instruction is the offset, that's pretty much useless," Karl complained.

"Why so?"

"How often are you going to have an offset larger than 256 when the array starts in page zero?"

"Good point. The architects of the 6502 knew this as well, probably from programming the 6800, and they provided a short indexed mode." Mr. Mori picked up another transparency, fixed it, and swapped it in.

"So you can put the base address in the index register and only use one byte for the offset. They were saving space in the op-code table, so the Y index register can't do this except for two instructions, load X and store X. And I'm not sure whether the guys who designed the 6502 did this for some reason or it just worked out that way, but this address mode wraps around in page zero, so you'll need to remember that, too."

I asked, "So the entire array has to fit in page zero?"

"If it doesn't, you'll have to use the 16-bit offset form for the parts that go beyond, which can get really awkward, or just use the 16-bit offset form for the whole array."

Bill said, "I think I can see that." 

"Of course, we can also do 8-bit constant base with 8-bit variable index with this addressing mode, as we have discussed before. Gotta fix this one, too." He did so, and swapped another transparency in.

Karl said, "And this still limits the useful size of arrays."

(Surprisingly, there are a lot of useful applications for microcontrollers that don't actually need any more than 256 bytes for any particular array, or even for all arrays. In fact, one of Motorola's corporate customers pointed this out to Motorola sales engineers, probably about the time I and my real-life classmates were beginning the Industrial Electronics class in the real world. And Motorola would respond by designing the 6805, which would be appropriate to describe as a half of a 6801 -- almost literally. Or maybe half a 68HC11. Only the accumulator A, only an 8-bit X. Some bit handling instructions not in the 6800 or 6801. But the 6805 and its descendants would become one of Motorola's biggest cash cows in your reality. Some analysts would estimate that descendants of the 6805 outnumbered all other microprocessors and microcontrollers delivered in the early 1990s, before ARM ..., but I'm getting way ahead of the story again.)

"If we had some way to work on all 16 bits of an address in memory and then use the result as an address, it would help, right?"

Karl grunted agreement. "I don't see any way to handle generalized arrays with just what you've described, except by what you said, multiple access functions or run-time self-modifying code. Is there a 16-bit index register hidden away somewhere?"

"That brings us to two more addressing modes in the 6502 which are called memory indirect addressing modes."

Bill said, "Indirecting from memory would be like indirecting through the 9900's working registers?"

"Sort-of kind-of pretty much like, the way I see it." 

Harvey added, "So X and Y are only eight bit, but the 6502 can use 16-bit addresses directly out of memory?"

"Directly indirectly." Mr. Mori grinned at his own joke. None of us students really got why it was amusing, just yet.

"Let's look at one of these addressing modes." Mr Mori swapped transparencies. "The first one is a kind of extension of the short indexed mode, but what you are indexing in the direct page is an array of addresses that the 6502 can load into its address buffer. You might use it something like this:" 

 

"Note that we are now scanning the list of addresses, not the string, with the index register. Maybe I should have shown the address buffer in this, but that might not be exactly accurate. Hmm. Let's give it a shot." 

Karl stood up and said, "So there is a 16-bit address register hidden in there!" 

Mr. Mori reworked part of the diagram while we watched. "Yeah, sort-of. Whether it's an actual 16-bit register or not, I don't know. But it's as if there is one there." 

 

Karl sat down as Frank said, "So you with this we can look at the length byte, but how would you scan the string?"

I suggested, "You could have a 16-bit variable that's an array of one, that you can copy the address to, and do address math on that like we did on the 6800, and then use this indirect mode on the array of one?"

"Might work, but what happens to X while you're doing that?" Mr. Mori asked.

Ted said, "I think it gets walked on."

I asked, "Can you use this mode with Y so you can keep X pointing to the array?"

Mr. Mori said, "You guys are thinking. Great. Y does have a little bit different use. Let's look at it." He swapped transparencies. 

"Oh, let me put that address buffer in here." 

He started reworking one part, then stopped again for a moment. 

"Except there must be two virtual 16-bit buffers, according to the timing charts. Or they figured out a way to reuse it pretty efficiently. Hmm." 

He reworked another part, as well. 

"I'm not sure, as you may have heard me just telling myself, whether the 6502 adds Y to the same address buffer it used to bring the address out of P, or whether there are two separate buffers. No guarantees on the actual accuracy of this diagram. Either way, hopefully, you can see something of how it works in this diagram."

I said, "So P in this is like Rick's and my X16 variable --"

Rick said, "That was your X16 variable, but, I think you're right. It looks like we can do math on that in memory, and then it can be used directly as a base address with Y as the index. Which overcomes the width and location problems like in the 6800, but without having to load and store the 16-bit X."

Bill said, "So, we could load an address from a table of string addresses indirecting from X, then move that address to P and use P to scan the string." 

Harvey said, "I think you'd use the X indirection to do something like checking the length of these strings, and if the length is in the right range, use regular indexed instructions to load the pointer to P, where you could use the Y indirection to scan the strings." 

Mr. Mori said, "Harvey, do you want to try writing some code to do that?"

"Uh, not really."

Mr. Mori picked up the marker from the whiteboard tray. "How about if Bill helps?"

Bill and Harvey looked at each other doubtfully, but Bill stood, and then Harvey stood, and they went to the whiteboard. Harvey picked up the marker.

Harvey said, "Do we put the address of the array of string pointers in X?"

Bill said, "Let's use the address for the constant part, like the example shows."

Chuck asked, "Could it go either way?"

Mr. Mori said, "Let's wait to think about that."

Harvey wrote

  LDX #4    ; 3rd string is offset 4

Bill said, "We need to get the length to look at it."

Harvey hesitated, and  then wrote

 LDA (N,X) ; N array is in page 0, get length of string

"Then what?" Bill asked.

Hec said, "We don't really know how this part works."

Mr. Mori said, "Just write something."

Harvey wrote

 (something) 

Everyone laughed, but Mr. Mori said, "Good." 

Bill said, "Assuming we can proceed, we need to load the address into P.

Harvey said, "And we do that byte-by-byte." He wrote,

 LDA N,X ; low byte of address
 STA P ; P is in page 0
 LDA N+1,X ; high byte of address
 STA P+1

Karl said, "Is that legal? I can see P plus one, but N+1 --" and he trailed off. 

Chuck said, "Bumping the constant for the base by one probably has the same effect as bumping the variable X  by one, doesn't it?" 

Mr. Mori said, "It does."

"Okay," Bill said. "We need the offset into the string."

"Put it in Y?" Harvey suggested, then followed his own suggestion.

 LDY #3 ; 3rd char after length

Bill said, "I guess we're ready to do whatever it was we were going to do."

Harvey said, "That was op B, wasn't it?" and wrote,

 opb (P),Y

"Did I get the parenthesis right, Mr. Mori?"

"That's the way I understand the syntax to work. Parentheses indicate indirection." Mr. Mori replied.

Mark said, "So the 6502 is carrying the concept of page zero as a bank of pseudo-registers a bit farther than the 6800."

"Thank you for pointing that out." replied Mr. Mori. 

I said, "But we still aren't really scanning any strings. We need some way to repeat things."

"True. Anyway, once you understand how these two modes work here, I think you'll be able to think of more ways to use them." 

Karl said, "I don't really see how modifying P is significantly different from modifying the address field of an instruction. If you modify P and then something interrupts and modifies it again before you can use it, you're still going to be using a wrong base address."

Mr Mori said, "Good point. One difference is, as Cyndy pointed out, that you are less likely to overwrite actual instruction object code with P. Another is that you can collect P with other variables that need to be swapped out and restored when an interrupt happens. It makes it easier to manage what needs to be managed."

Karl set his mouth in thought. 

Mr. Mori let us think some more before continuing. "Now there's one more mode, and I want to mention it. It's a mode only for jumps, that they call absolute indirect in the docs. An absolute jump moves program flow to the 16-bit address that the instruction specifies. An absolute indirect jump moves program flow to the 16-bit address that is stored at the address specified in the instruction."

Barry said, "So, the absolute jump is like load PC immediate, and the absolute indirect jump is like load PC absolute?" 

Scott and Bob groaned, but Mr. Mori said, "That's another way of looking at it, but I'm afraid some of our students will be confused.

Mark stood up and went to the whiteboard. 

Mr. Mori said, "Looks great. There is a bug in this instruction, however. When the instruction specifies an address with a low byte of 255, it grabs the low byte of the new PC from the proper place, but then wraps the address around to get the high byte instead of incrementing."

"So we should never give it an address that ends in hexadecimal $FF, then," Mark said. He wrote in a note next to address 2101, "Don't use JMP (0XXFFH). No 255 in low byte.".  And he put the marker back and sat down.

"Correct."

Mr. Mori shut the overhead projector off, leaving it in place to cool.

"We've been burning the brain oil, so let's shift gears and look at your letters of inquiry." He moved an opaque projector in beside the transparency overhead projector.

"About your letters of inquiry, Ms. Wilson informs me that she will not allow Cyndy and Joe to type anybody's letter of inquiry for them in the school's typing lab. I must say that she has convinced me of the folly of the plan."

There were a few scattered groans and complaints, along with some "Of course." and such.

"On the other hand, she did have an another plan, and I think it's a better plan. She thinks she might be willing to hold the computer lab open after school for you guys to go over in small groups, and she can coach you and then let you type them up yourselves. But she needs to check with administration first."

Responses shifted a bit more to the positive.

"I think most of you realize that typing is a useful skill when you're working with computers. So if she gets approval, this could be a good opportunity. But you must all understand that, if you do this, you must treat the typewriter lab equipment with respect, no less respect than our electronics lab."

Mark said, "No playing football with the typewriters, Karl."

There were scattered chuckles. 

"Hey!" Karl objected. "I know how to throw a typewriter respectfully."

More chuckles. 

Mr. Mori gave us an indulgent frown. "Getting yourselves kicked out of school would leave us short of students again. Don't do that." 

There was scattered laughter.  

Rick and Hec shook their heads.

Cyndy's eyes grew wide with concern.

I gave it all an eyeroll.

"Guys," Cyndy exclaimed, "Think of what Ms. Williams would say if she heard this. She'd probably change her mind."

The jesting suddenly stopped.

Karl coughed. "Sorry, Cyn. Just kidding."

"'Cyndy', to you."

Karl ducked his head in apology. 

"The problem with jokes is when they suddenly quit being jokes," Mr. Mori's voice was sober. "There are parts on those electric typewriters that I'm sure some of you will be tempted to get your fingers into or treat like balls. I don't want to have to be this way, but I will have to have promises from everyone who goes to behave yourselves. I may even need a permission slip from your parents."

Mark said, "I guess that was partly my fault, too, leading off like that. Sorry, Karl. Sorry, guys." 

There were general murmurs of agreement, and Mr. Mori let them die down. 

"So, Joe," he shifted gears. "Do you have your letter with you?" he asked as he turned the opaque projector on.

Cyndy gave me a querying look, and responded before I could. "I have mine typed up." She slipped it out of her notebook and handed it to Mr. Mori while I got my copy from the typing class out.

He looked puzzled, and accepted Cyndy's, but turned to me. I handed him the letter I had typed at school. 

Rick glanced over at me. "You kept a copy, then. Smart move." 

Mr. Mori looked them both over, then said, "It looks like you both did a bit more editing before typing these up yesterday."

"Ms. Wilson made some suggestions," Cyndy explained before I could.

"Nice of her."

Cyndy was still querying me with her eyes. 

"We've been asked to be careful about showing students' actual addresses and phone numbers in class, do you mind if I mark out your address and phone number and show this to the class?"

"No problem, either way," I replied. "But, for the record, that's not what I actually sent."

"Sent?" Mr. Mori gave me a quick look.

"I guess I got impatient last night." 

He blinked at me. "You have a typewriter at home?"

"Dad does, but I sent it handwritten. I was careful to make it legible."

Mr. Mori looked non-plussed. "Administration wants copies of every letter sent. I don't guess you made a copy of it?"

"Scratch copy in pencil, with mark-up," I said as I turned to dig into my notebook for the scratchwork, but Cyndy was holding a piece of paper up for me.

It was my turn to to give her a querying look.

"You might want this," she said, quietly, with a knowing smile.

I blinked and accepted it. 

It was my own writing, the letter I thought I had sent the night before. 

"What? How on earth?"

Cyndy smirked and kept her voice low enough only Hec and Rick and I could hear. "She said you didn't notice."

"She --" I kept my voice low as well.

Mr. Mori watched our exchange with interest. 

"Writes fast. And accurate." 

I gave an embarrassed laugh and covered my eyes with the letter for a moment before handing it over to Mr. Mori without comment. 

"Secrets?" Mr. Mori asked. He looked at Hec, who shrugged.

"Well, good for you, you did make a copy. Does not look like pencil, though. And I don't see any mark-up."

I coughed. "I'm going to have to blame this one on my study partner."

"Good for you, Cyndy, although you might have gone so far as to encourage him to be more patient."

"Hec and I studied at my house last night." 

"Rick?"

"Different study partner," Rick said. 

Mr. Mori gave the four of us a look and said, "Curiouser and curiouser."

None of us volunteered more information.

He chuckled. "Well, let's take a look. I'll go ahead and mark out your address and phone number." 

He compared mine with Cyndy's and said, "I think I'll start with Cyndy's after all." 

He marked her address and phone number out and put her letter on the platen and adjusted the projector. "Okay, she uses standard greeting --"

"What happens," asked Harvey, "if they aren't sirs?"

"'Dear Sirs' is standard greeting. They won't be upset. Odd-ball greetings will not impress anyone."

"Oh."

"She identifies herself and our school, and our class. She gives my name as the teacher and the school address and contact information we showed you yesterday.

"Then she explains her interest in the 8080, that we will be studying it in class. It's a little bland, but that's actually good. 

"And she asks for information on how to obtain documentation for both the microprocessor and its support parts. And she closes. 

"Clean grammar, no attempts to dress things up. No particular reason to refuse the request. She will likely get some standard advertising material, a list of parts that she can request information about, and a standard order form for the datasheets." 

He looked around the class. "Any questions?" 

Nobody thought of anything immediately.

"Okay." He took Cyndy's out and gave it back to her, and replaced it with my typewritten inquiry, after marking out my address and phone number.

"We see Joe has done essentially the same here. You'd think they typed these up together yesterday in typing class." He chuckled to himself. "But you can see some differences in expression. Which do you guys think is more likely to get a good response?"

We spent a minute or two critiquing Cyndy's and my different ways of wording things.

"Okay." He gave me back my typewritten letter, then marked my phone number and address off the handwritten letter and put it on the platen. "In this version, Joe is explicit about his interest in the 6800. He isn't just interested in it for class, he thinks there are advantages. He even goes so far as to name all the microprocessors we are studying. 

"I'm not sure that's a good idea. I'm not sure it's a bad idea. It is something of a sales pitch approach, however, and we need to be aware that it may be received as insincere. It may also be received as ambitious."

"The inquiry itself, he's becoming more ambitious. In addition to information on the CPU and related parts, he's asking for information about development tools.

"Now, whoever handles this at Motorola might not think about a student wanting to know about development tools. The development tools aren't cheap, and they may wonder whether Joe understands that. I do think they are more likely to reply with some information about development tools, since he asks.

"But he does sound like a kid who's asking bigger questions than he realizes. Sorry, Joe."

I nodded. 

He continued, "On the one hand, I don't recommend Joe's approach in general. Smaller companies without secretary staff, an engineer may get the letter and tend to set the inquiry aside to respond to when he has more time to think about it. On the other, I'm not sure it would hurt with Motorola, they are a fairly large company, and it is more likely the letter will be handled entirely by a secretary. I guess we'll see." 

He took my other letter off the platen and gave it back to me. "Harvey, are you willing to let us see yours?"

"Uh, sure." He already had his out, and handed it to Mr. Mori. "No problem if you mark out the address and phone number."

Mr. Mori scanned it. "Okay, here we see some differences." He marked out the personal information and put Harvey's letter on the platen. "Harvey is sending his to Apple, which is a company selling computers, not a company selling microprocessors. Well, selling the mainboard. So what he is asking for is comprehensive information on what the mainboard includes, and what options Apple sells for it at that apocalyptic price, which, low as it is for a computer that is almost complete, is enough to buy a pretty decent used car."

He looked up. "The letter is okay, but you guys should know. The apocalyptic price does not include the TV used as an output device. It also does not include the keyboard, power supply, or a cassette interface. So there is some assembly required. And Apple is selling them so fast they really haven't had time to print up a lot of the documentation materials that they might be willing to send to students.

"I don't want to discourage you, Harvey, but you might do better just sending an inquiry to MOS Technology about their KIM-1. It doesn't output to the TV, but it's much cheaper, and you can ask about the 6502 and peripheral parts at the same time. You might want to reference Joe's letter." He handed Harvey back his letter.

"Do you mind, Joe?" Harvey asked.

"No problem." I passed my second letter over to him, and he started copying from it.

Rick said, "Harvey, can I check your letter for ideas? I'm going to be sending mine to Southwest Technical Products, to ask them about their 6800-based computers."

"Sure." Harvey passed his letter to Rick. 

Mr. Mori asked, "Anybody get a letter to RCA or TI?"

Hec said, "I've got one to send to RCA, but it basically looks like Cyndy's."

I said, "You might want to take a look at the COSMAC manual over at OC before you send it."

Hec looked thoughtful. "Maybe so." 

Mr. Mori looked at Ted, but Ted shrugged and didn't say anything.

"Well, we're close to the bell. I'll let you guys clean up your notes or work on letters of inquiry."

I went to the front of the room and looked through more magazines while Rick worked on his letter. I found an ad for the MEK6800d1 and read it before taking it back to show Rick.

Hec read a little over Rick's shoulder and then went back to the magazine stack and thumbed through more magazines, finding an article on the COSMAC ELF, which he brought back to the table. Cyndy read over Hec's shoulder. When Harvey brought my letter back and Rick gave him his back, he saw what Hec and Rick were looking at, and went up and thumbed though more magazines, finding an ad for the KIM-1.

We passed the magazines around, and Barry dug up an ad for Intel's SDK-80 in another magazine. No one was able to find ads for any similar devices for the 9900.

While we were digging around in magazines, Mr. Mori was talking with Chuck. 

After class, Mr. Mori snagged Ted to talk. Ted seemed hesitant. 

Cyndy and Hec left together, deep in discussion. Rick and I headed out, and met Sapphire outside Rick's next class, and Sapphire and I walked to the typing lab together. 

"Mom suggests that we should study where others are around."

"Oh?"

"My leaving early for your seminary seemed to worry her."

"We'll have to see what she feels comfortable with, I guess."

"But there are things I need to ask you that I won't feel comfortable about if there are other people around."

"I'm sure we can figure something out."

We stayed outside the classroom, holding hands and not saying much until Cyndy approached, and we went inside. 

 

TOC
Next
Where it starts

Copyright 2026 Joel Matthew Rees



[CUTTING ROOM FLOOR] 3809/2801: M6800 EXORcises to 6502 Indirection

Scraps from the cutting room floor,
from around M6800 EXORcises to 6502 Indexing

This is the author's record of some of the stuff that got discarded; 
taken out of order, 
it does not tell things hidden things that happened,
or indicate directions the plot will take, etc. 

More than what is here,
you should want to read the story,
which begins here:  
https://joelrees-novels.blogspot.com/2025/09/3809-2801-tale-of-mcus-and-time-part-1-2801.html

2801
Terms of Engagement
Cutting Room Floor

M6800 EXORcises


TOC


"We've been asked to be careful about using students' actual addresses and phone numbers in class, so I'll mark them out." He did so and put the letter on the opaque projector. 

He commented on my letter and asked the class for comments and questions, and then he handed it back to me. "Looks good to send it like this. I hope you don't mind a little extra practice typing it again."

"No problem. I already sent it last night."

"Oh." He raised his eyebrows. 

He turned to the class and said, "I don't see anything on Cyndy's letter to comment on, so I'm not going to ask her to let me mark hers up." He handed it back to her. "I think you can send it like this."

"Anyone else with a letter of inquiry that you want comments on?"

Hec handed his to him, and he scanned over it. "Cyndy typed this up?"

"Yeah."

"Do you mind if I mark out the address, Cyndy?"

"Sure. It's okay."

After discussing some points on Hec's letter, he handed it back. "Sorry about marking it up, Cyndy."

"No problem."

Rick and several other students gave him hand-written letters to look over, and he offered pointers and handed them back. 

 

*******

"True. Anyway, once you understand how these two modes work here, I think you'll be able to think of more ways to use them." 

 He paused again, to let us think, before continuing. "Now there's one more mode, and I want to mention it. It's a mode only for jumps, that they call absolute indirect in the docs. An absolute jump moves program flow to the 16-bit address that the instruction specifies. An absolute indirect jump moves program flow to the 16-bit address that is stored at the address specified in the instruction."

 

********** 

"So, Joe, do you have yours with you?" he asked as he turned the opaque projector on.

Cyndy gave me a querying look, and responded before I could. "I have mine typed up." She slipped it out of her notebook and handed it to Mr. Mori while I got my copy from the typing class out.

He looked puzzled, and accepted Cyndy's, but turned to me. I handed him my typed copy of my earlier draft. 

Rick glanced over at me. "You kept a copy, then. Smart move." 

Mr. Mori looked them both over, then said, "It looks like you both did a bit more editing before typing these up yesterday."

"Ms. Wilson made some suggestions," Cyndy explained before I could.

"Nice of her."

Cyndy was still querying me with her eyes. 

"We've been asked to be careful about showing students' actual addresses and phone numbers in class, do you mind if I mark out your address and phone number and show this to the class?"

"No problem, either way," I replied. "But, for the record, that's not what I actually sent."

"Sent?" Mr. Mori gave me a quick look.

"I guess I got impatient last night." 

He blinked at me. "You have a typewriter at home?"

"Handwritten. I was careful to make it legible."

"I guess you didn't make a copy of that?"

"Penciled, with mark-up." I turned to dig into my notes for the scratchwork, but Cyndy was holding a piece of paper up for me.

It was my turn to to give her a querying look.

"You might want this," she said, quietly, with a knowing smile.

I blinked and accepted it. 

It was my own writing, the letter I thought I had sent the night before. 

"What? How on earth?"

Cyndy smirked and kept her voice low enough only Hec and Rick and I could hear. "She said you didn't notice."

I gave an embarrassed laugh and covered my eyes with it for a moment before handing it over to Mr. Mori without comment. 

"Well, good for you, you made a copy. Does not look like pencil, though."

I coughed. "I'm going to have to blame this one on my study partner."

"Good for you, Cyndy, although you might have gone so far as to encourage him to be more patient."

"Hec and I studied at my house last night." 

"Rick?"

"Different study partner," Rick said. 

Mr. Mori gave the four of us a look and said, "Curiouser and curiouser."

None of us volunteered more information.

He chuckled. "Well, let's take a look. I'll go ahead and mark out your address and phone number." 



******* Need to talk about coordinating queries 

"So we should never give it an address that ends in hexadecimal $FF, then," Mark said. He wrote in a note next to address 2101, "Don't use JMP ($XXFF). No 255 in low byte.".  And he put the marker back and sat down.

"Correct."

Mr. Mori shut the overhead projector off, leaving it in place to cool.

"We've been burning the brain oil, so let's shift gears and look at your letters of inquiry." He moved an opaque projector in beside the transparency overhead projector.

"So, Joe, did you bring a copy of your letter?" he asked as he turned the opaque projector on.

Cyndy gave me a querying look, and responded before I could. "I have mine typed up." She slipped it out of her notebook and handed it to Mr. Mori while I got my copy from the typing class out.

He looked puzzled, and accepted Cyndy's, but turned to me. I handed him my copy. 

He looked them both over, then said to me, "Do you mind if I mark out your address and phone number and show this to the class?"

"No problem, either way," I replied.

"We've been asked to be careful about using students' actual addresses and phone numbers in class, so I'll mark them out." He did so and put the letter on the opaque projector. 

"It looks like you did a bit more editing before typing this up."

"Ms. Wilson gave me some pointers."

"Good of her."

He commented on my letter and asked the class for comments and questions, and then he handed it back to me. "Looks good to send it like this. I hope you don't mind a little extra practice typing it again."

"No problem. I already sent it last night."

"Oh." He raised his eyebrows. 

He turned to the class and said, "I don't see anything on Cyndy's letter to comment on, so I'm not going to ask her to let me mark hers up." He handed it back to her. "I think you can send it like this."

"Anyone else with a letter of inquiry that you want comments on?"

Hec handed his to him, and he scanned over it. "Cyndy typed this up?"

"Yeah."

"Do you mind if I mark out the address, Cyndy?"

"Sure. It's okay."

After discussing some points on Hec's letter, he handed it back. "Sorry about marking it up, Cyndy."

"No problem."

Rick and several other students gave him hand-written letters to look over, and he offered pointers and handed them back. 


****

 

"I've arranged with Ms. Wilson to make typewriters available in the typing lab after school. They have correcting ribbon, so you don't have to type perfectly. But if you're confident you can use handwriting that doesn't cause the secretary and managers that will be reading your letters eyestrain, you can write them by hand, too. Just," he gave me another look. "Let me check them before you send them. And make a copy for me to refer to in case the companies you contact contact the school. And keep another copy for yourself."

 

FTR, from the reality chapter: "I pulled out my query letter and looked it over, and decided to add a few things to it, mentioning the other processors we were studying, and making my interest in the prototyping kit pricing explicit. I wrote it out by hand in pencil, erasing and rewriting until I thought my additions were clear enough, then hand-copied it with a pen."  

 

 

(Besides, it's a little hard to remember all of what happened so long ago.) 

 

 

 

 

 

(Descendants of the 6502, by the way, are still being used in new designs as I write this.) 


*******

constant base, 16-bit array anywhere in memory, but width limited, methods exist to get around width

variable base/constant offset must start in page zero -- mention direct page is page zero

mention instruction differences, unary (RMW) not available to Y

 

8-bit constant short form exists, but wraps around, and only for X index instructions plus LD/STX ,Y indexed  

 

indexed indirect for table of indexes in page zero (index half bytes wrap in page zero), X points to index in page zero

 

indirect indexed is for base address in page zero (base halves wrap), Y has offset

 

Mark said, "So the 6502 is carrying the concept of page zero as a bank of pseudo-registers a bit farther than the 6800."

"Thank you for pointing that out," replied Mr. Mori. "Once you understand how these two modes work here, I think you'll be able to think of more ways to use them."

We spent some time discussing indirection and byte order, letting the students who hadn't quite kept up catch up. I'm sure you've kept up okay, so I'm going to skip all of that. 

(Besides, it's a little hard to remember all of what happened so long ago.) 

 

 

is basically loading an immediate 16-bit value into the program counter. An absolute indirect jump, then, is loading the program counter from the 16-bit address specified in the instruction.


"If you hand-write the final copy to send in, write neatly enough that the secretary that reads it doesn't have to strain her eyes. I've arranged with Ms. Wilson to let those of you who want to try typing your own borrow typewriters with correcting ribbons in the typing class, if you want to do it that way. Either way, keep a copy before you send it, so we can refer to it. 



(Descendants of the 6502, by the way, are still being used in new designs as I write this.) 


 

*******

"Something like this?"

Pete said, "So I guessed right?" 

"I guess you did. What else is different about it, say, from the 6800 and 9900?"

"Little endian," Harvey said.

"Yep. The 6502 puts its low byte first, like the 8080 and the 1802." 

Bill asked, "Are X and Y interchangeable?"

******

"Okay, Harvey, you said the 6502 has two index registers, but they are only eight bits wide, right?"

"I think so." 

"And, Pete, you mentioned a 16-bit index constant part for the instruction."

"I thought it might be a possibility."

"What benefit would it have?" 

"When you know an array's address, it could start anyplace in memory. But the index register would limit its width." 

"Mr. Mori put a transparency on the projector.

 

"And there you are. Remember that the 6502 puts its low byte first."

"Little endian," Harvey said.

"Yep. There are some differences about which instructions can be used with Y indexed addressing and with X indexed addressing. You might not know what I mean if I say X indexed is provided for both unary and binary instructions and Y indexed provided for binary. But file that fact away for now." 

Ted raised his hand. "Unary instructions are read-modify-write instructions, right?"

"You're trying to confuse everyone."

"Sorry."

Mr. Mori grinned. "Just kidding. You're right and we'll talk about that later. "

He paused. "Can you think of a way of getting around the width limitation?" 

I suggested, "Use the middle of the array for the constant base address?" 

Mr. Mori nodded. "Can you tell us how to do that?"

While I was thinking, Frank raised his hand.

"Frank?"

"If the array is larger than 256 bytes but smaller than 513, provide one routine to point into the low half and another to point into the high half, and figure out somehow which half you're needing to point to choose which routine to use."

"Very good, and we'll talk about how to actually do that later, as well. There's another way that involves modify the constant base in code at run-time, but I do not want to teach you that."

"Why not?" Karl asked.

Cyndy said, "You might modify the wrong part of the instruction?"

"There's that. What else?"

Frank said, "You might modify the constant part of the instruction once, and something might interrupt the code so that it fails to restore it before the next time you try to access the array." 

"Excellent. And the guys who designed the 6502 knew that could happen, so they gave us another way, which we aren't quite ready to talk about yet." 

He swapped transparencies. "Just to be complete, what does our 16-bit constant offset and 8-bit variable base address mean for arrays when you don't know where they begin until the program runs?" 

 

 

After some consulting with each other and with the class, they came up with this: 



Once you see this, you may be able to think of other ways to use these two modes, but I think this is basically what they were thinking of when they chose the modes to support."


 

 

 

****** 

Rick said, "I think I should be, as well."

"Okay, okay." I stood up and  


"And if the constant offset from the instruction stream is only eight bits?"

"Then all arrays have to start in page zero and be less than 256 bytes in size?"

"It gets even stranger than that with some instructions." 

"Yeah. Let's talk about that." 

***** 

"Okay, Harvey, what's peculiar about the 6502?"

"It has two indexes, but they are both 8 bits wide?"

"That's one thing." 

"If the constant base address can be sixteen bits wide, we have the opposite problem from the 6800."

"How so?"

"A sixteen-bit constant base can put the array anywhere, and we'd be okay as long as the offset is less than 256. But that only works when we know where it is in advance."

"That's true. The 6502 provides this mode, and I understand that we can do with both X and Y. Would you be willing to diagram it for us?"

Harvey hesitated. "I guess I can give it a try." He approached the white board.

 

*** 

 

 

"Joe left the steps to add the two bytes out of the diagram. Is that confusing to anyone?"

Several of the guys raised their hands.

"Okay, Joe, do you mind if I take over for a bit?"

"Sure. I mean, no problem."

"Okay, we're going to role play the computer." Mr. Mori grinned and paused for effect before continuing. "When I call you, stand up. Joe, you and Rick remain standing. Scott, you're direct page memory location X16. But we need an actual address. Rick, what's the actual address?"

"I don't know. Ten, maybe?"

"Ten it is. Barry, you're location X16 plus one. What's your address?"

"Uh, eleven?"

"Okay, Bob, you're accumulator B. What do you have when the code starts here?"

"Four."

"Right. Karl, you're the index register, X. What have you got?" 

"N."

"We need a concrete value for N so Barry and Scott know what hits them." 

"Anything less that 65,536?"

"What do you say, Joe?"

"I have the impression that addresses above 32,767 get used for stuff, so maybe below that."

"How about 31,999?"

I shrugged "I think it would be okay, but we have to divide that into high byte and low byte."

Karl looked at Barry with a grin. "You do the math."

"Well, 32,000 divided by 256," He looked at Mr. Mori, who nodded. "Is a hundred twenty-five, so the high byte is 124."

Scott nodded. "And the low byte is 255."

"Okay. But you don't have those yet. What do you have?"

Barry said, "Something random?"

"Probably."

"Okay, I have seventeen."

Scott said, "I'll have a hundred seventeen." 

Mr. Mori said, "Now we need someone to be the carry flag. Mark?" 

"Okay. I'm random to start, too?"

"Yeah."

"No carry, then." 

"Okay, Joe, read the instructions."

"Store X at location ten."

Karl said, "Scott first?"

"Yeah."

"Scott gets one twenty-four." 

Scott said, "124."

"Barry gets two fifty-five."

Barry said, "255."

I said, "Now, add B from location eleven."

Barry said, "255."

Bob said,  "Four and two fifty five makes --" he stopped. "I can't hold anything bigger than 255, so it wraps around to three, with a carry, I guess?"

Mark said, "Carry." 

I continued, "Store B to location eleven." 

Bob said, "Three."

Barry said, "Three."

Mark said, "Carry unaffected?"

I said, "Right. Now load B from location ten."

Scott said, "One twenty-four."

Bob said, "One twenty-four."

Mark said, "Carry unaffected, still?"

I said, "Right. Add constant zero to B with carry."

Mark said, "Carry."

Bob said, "One twenty-four plus one is one twenty-five."

Mark said, "No carry."

I said, "Store B in location ten."

Bob said, "One twenty-five."

Scott said, "One twenty-five."

Mark said, "Carry unaffected, no carry."

I said, "Load X from location ten."

Scott said, "124."

Barry said, "3."

Karl said, "Man this gets boring."

Mr. Mori said, "It's a good thing CPUs don't get bored, isn't it?"

We all laughed.

Karl grinned. "Well, anyway, X is now 32,003." 

I said, "And we are finally ready to do whatever op-code C was, but it's in indexed mode, and the index byte is zero."

"Yay," Karl said, and we all laughed.

Mr. Mori commented, "I don't see a return instruction."

"Is that what makes code reusable?" Rick asked.

"If your code is constructed correctly," Mr. Mori replied.

"We haven't got that far yet," I apologized.

"That's okay. We'll get there. But this prepares us to talk about the 6502."

Rick asked, "Can we all sit down, then?"

"Sure." 

We all laughed and those of us standing sat down.


 

 

But what if we don't know the base address ahead of time?"

"You're going to tell us about it?"

"Give me a hand drawing this.  

 

 

 

 

 

************* 

Draw a picture of string with constant offset, 

then array in direct page with variable offset, 

then adding the offset to an index variable in memory


6502: 

introduce absolute index on X and Y, instruction limits, and direct page index on X, instruction limits and Y for LD/ST;

Motivate the 16-bit base address problem, introduce simple memory indirect and instructions that use it.

indirect indexed ([base,X] or [offset,X] points to list of addresses)

indexed indirect ([base],Y points to the operand  

absolute indirect jump only

 

***********************


 

 

I found the right section in the stacks just as a library assistant brought Rick over.

"IBM 370," I announced quietly.

"Mainframe," Rick replied, also quietly. He read a spine. "PDP-11." He reached for the DEC manual.

"I think that's a minicomputer."

"So not a microcomputer." His hand paused.

"Mmm." I nodded.


 

Sapphire waiting in classroom? Karl or somebody joking about Joey? Hold it off?


Chapter five, section one dot two, eh, page five dash twelve."

 

"We're going to have to see if we can meet you guys there, then. You think, Cyndy?" 

"Yeah, I think so."

"I get to come along?" Sapphire asserted.

"Saturday?" I suggested. 

 

"Addressing modes, instruction set, pointer operations, branch and jump, looks like it repeats a lot of the information in the Programming manual. Hmm." 

Rick's eyes met mine, but he didn't say anything. He looked back down and continued flipping through the pages. 

I looked back down and continued. "Addition and subtraction routines, multiplication and division, counting." 

I opened to section two and read without a lot of comprehension. 

"Alpha, beta, gamma. Well, I suppose, if it's a small number and fits in an accumulator, adding requires loading the number to be added to, adding the number to add to it, and storing the result."


I moved past the table of contents

 

"Hmm. This looks like an electronic cash register," I muttered as I flipped through the pages of the manual I had. "Instructions on how to use Motorola parts to put together a point-of-sale terminal, including the programs. Complete with bar code reader." 

Rick put the Programming manual down and shifted his chair so he could read over my shoulder. 

 

I kept flipping pages and got part way through chapter 7, and stopped to look at the image at the beginning of section 2, which appeared to be a non-descript box of electronics with very few controls -- only a keylock between a couple of what appeared to be pushbuttons, with three indicator lamps or LEDs above those, on the right side of a front bevel swept back towards the top, with an exaggerated lip along the bottom edge. A large, black, blank faceplate covered an an inset open area to the right of the buttons, extending across maybe three quarters of the front panel.

"EXORciser?" Rick read the section title out loud, and hummed the signature opening phrase from Mike Oldfield's "Tubular Bells".

"For getting the demons out of our designs?" 

We both laughed. 

"Somebody at Motorola must have a sense of humor." He shook his head. "Looks kind of like a squashed toaster oven." 

"No blinking lights?" I turned the page. "Seventeen inches wide, nineteen deep, seven high. Forty-five pounds." I turned the page back.

"The Altair 8800 looks a lot more interesting, with the switches and lights on the front panel."

"I wonder if we could put that kind of front panel on this."  

"I wonder how much it costs, and what you can do with it."

 

 

Which we did when we arrived at the library. 

The librarian took us to the section where the microprocessor books were.

"These are reference works, so we can't let you check them out," she advised us, pointing out the sign of the shelves that said the same thing.

"Thanks." 

 

"Hmm, Intel 8080. IBM 360. Fairchild F8. What's that?" Rick picked up one of the Fairchild manuals and thumbed through it.

"Here we are, Motorola M6800." I picked up one of the Motorola manuals and started thumbing through it.

"Do you need anything more?" the librarian asked.

"Do you know if you'll be getting manuals for other processors?" Rick asked.

She gave Rick a thoughtful look, and said, "Let me check." 

While she went to check, Rick looked at the F8 manual, and I looked at the Motorola manual.

"Wow." Rick muttered. "The F8 looks even more primitive than the 1802." 

We thumbed through the manuals. 

"What have we here?" I muttered. "Source code and engineering diagrams for an example cash register controller."

Rick put the F8 manual down and started looking over my shoulder. "I might be able to make some sense of that," he said.

We continued to peruse the source code for a few minutes, and the librarian returned.

"The electronics technology staff has requisitioned manuals for the, uhm, Western Design Center 6502 and a couple of Texas Instruments microprocessors," she said.

"9900?" Rick asked.

"That's the one," she answered. "Both seem to be really new products."

"That's what we understand," I responded. 

"If you give me your names and phone numbers, we can let you know when we get them."

We did so, and thanked her.


 

 

 

"Oh." Rick put his car in reverse, checked his mirrors and over his shoulder and backed out of the parking space. "I guess that explains it." 

We headed for the college.

"Maybe," he added.

"You don't believe me? You could come to Seminary, you know."

Rick laughed. "Maybe I should. Just to keep an eye on you two."

 

 

The calculus class was on the second floor of Wilkerson Hall, and we passed my dad's office on the way. But Dad was in class, so we didn't see him. 

In the calculus class, Professor White held up a loaf of pumpernickel.

"How are we going to measure the volume of this loaf of brot?" 

Rick raised his hand. "Cut it in slices and measure each slice?"

"You've been reading the text. Good for you."

One of the girls whose name I don't remember suggested, "Or he saw the sliced loaf on your desk."

"Being observant is also good." Professor White lifted the tray of sliced pumpernickel. "Now, how do we measure each slice?"

"Slice up a slice?" I suggested.

"Excellent. Now, could you draw that on the chalkboard?"

 

Professor White explained sums of infinitesimals, inviting us to thing of real-world examples, waxing excited about the elegance of correct solutions, calling correct math sexy.

After class, I suggested, "Hey, I wonder if there's any docs on microprocessors in the library."

Rick looked thoughtful. He said, "We probably do have time to check."

At the library, I headed for the card catalog. Rick asked at the checkout counter. We both ended up in the stacks about the same time.

"Please note," the librarian who helped Rick said, "that this is a reference shelf, and these books cannot be checked out." 

"Got it," I answered, and Rick nodded. 

"Hmm, Intel 8080. IBM 360. Fairchild F8. What's that?" Rick picked up one of the Fairchild manuals and thumbed through it.

"Here we are, Motorola M6800." I picked up one of the Motorola manuals and started thumbing through it.

"Do you need anything more?" the librarian asked.

"Do you know if you'll be getting manuals for other processors?" Rick asked.

She gave Rick a thoughtful look, and said, "Let me check." 

While she went to check, Rick looked at the F8 manual, and I looked at the Motorola manual.

"Wow." Rick muttered. "The F8 looks even more primitive than the 1802." 

We thumbed through the manuals. 

"What have we here?" I muttered. "Source code and engineering diagrams for an example cash register controller."

Rick put the F8 manual down and started looking over my shoulder. "I might be able to make some sense of that," he said.

We continued to peruse the source code for a few minutes, and the librarian returned.

"The electronics technology staff has requisitioned manuals for the, uhm, Western Design Center 6502 and a couple of Texas Instruments microprocessors," she said.

"9900?" Rick asked.

"That's the one," she answered. "Both seem to be really new products."

"That's what we understand," I responded. 

"If you give me your names and phone numbers, we can let you know when we get them."

We did so, and thanked her.

"Are we going to eat lunch?" Rick asked as she returned to the checkout counter.

"I guess we can look at these some more tomorrow," I answered.

We left and got in his car and headed for the Whataburger down the road.

"Onions today?" Rick joked as we pulled into the drive-in.

I chuckled. "Is that relevant?" 

But I did order onions, lettuce, tomato, pickles, and cheese, with ketchup and mayonnaise. Rick ordered a grilled chicken lunch.

We talked about math and electronics while we ate, and then headed for Permian. 

As we pulled into the east student parking lot, Rick said, "Look who's here."

Sapphire was waiting outside the south-east wing entrance. I waved, and she waved back.

"What's up?" I asked, as we approached.

She shook her head. "Just missing you."

I could feel Rick's eyes roll, even though I didn't look to check.

"I'm kind of, I don't know. You're seminary was --"

Rick filled in, "Wild? Cult-like?"

"Hey," I complained.

"Wild, yes. Cult-like, no. Just things I never knew about Moses and Abraham." 

"Maybe I should come to your Seminary to protect Sapphire," Rick suggested.

"Ah, how sweet." She gave him a moue.

"Stop. I'm melting." Rick chuckled.

The electronics classroom/lab was the easternmost room of the south wing, so we talked outside until a few minutes before the bell, and Sapphire hurried for her class.

"You know you're welcome to visit the Seminary class any time."

"I need my beauty sleep."


TOC
Next
Where it starts

Copyright 2025, 2026, Joel Matthew Rees






3809/2801: 6502 Indexed Addressing, Including Memory Indirect

2801 6502 Indexed Addressing,  Including Memory Indirect ALUs, Register Indirect Review,  Role Playing the 6800 ...