Monday, July 20, 2026

3809/2801: ALUs, Register Indirect Review, Role Playing the 6800

2801
ALUs, Register Indirect Review,
Role Playing the 6800

Motorola M6800 EXORcises
TOC

When we walked into the southeast wing from the entrance closest to the Permian student parking, Hec, Cyndy, and Sapphire were talking in the hall outside the electronics lab.

"There she is, Mary."

I glanced aside at Rick with a raised eyebrow before raising my left hand. "Greetings, earthlings," I said as we approached.

Hec cocked his head sideways, and Cyndy gave me an eye-roll.

Sapphire gave me a sour moue. "Hah. You only think you are of a superior race," she jested, before reaching out for my hand. I gave her hand a squeeze before we both dropped our hands a little guiltily.

Rick laughed. "Nope. Nothing to see here, folks." 

Sapphire gave him a look of mock innocent perplexity.

He just grinned. 

"How was calculus?" she asked.

"No class today, we just studied in the library," Rick answered. "Found some microprocessor manuals. They have the 1802 manual, too, Hec."

"You didn't check it out for me?"

"The manuals are all in the reference section," I explained.

"So you can't check any of them out," Cyndy said, somewhat wistfully.

"We could meet at the library, I think," Rick suggested. "Although the only time after school I'll be able to do that will be Friday or Saturday evening. Or Sunday."

"Do you guys have a game Saturday?" I asked. 

"Friday," Sapphire answered. "Which raises a question. Will you and Rick will be with us at the games?" 

Rick and I looked at each other. 

"I'm going to have to think about this," Rick said.

I nodded. "I think I'm game for it, but maybe not every game. You're not asking Hec. I guess he's committed?" 

"I'm like you, not every game," Hec replied. "But I'm a student here."

"Which raises a question," Rick pointed out. "Are there going to be riots on the field or in the schools if OHS students are dancing with the Permian cheer dance team at game time?"

I grimaced. "You could have talked all day, ..."

"But somebody has to ask," Cyndy finished for me. 

We all stood in silence for a moment or two.

I spoke up. "I guess I was hoping Ms. Michaels would run that question past the school staff."

Sapphire said, "Well, yeah. Ms. Michaels wants to know what you and Rick are thinking before she starts a discussion."

Rick looked at me and I nodded. 

"So, not this Friday," I said. "I'm not sure we're going to be that much up to speed anyway."

"Sapphire, you need to get to class," Cyndy reminded her.

"That's true. We can talk about it later?"

Rick and I nodded.

Sapphire touched fingers with Cyndy and reached out to me. I met her hand with mine and we gave each other's hands another squeeze, and she left. The four of us entered the classroom.

As we sat down, Hec asked, "What happened between you two last night?"

"Who?" I dodged.

"You and Sapphire," Cyndy said. 

"We just studied and talked," I replied.

Rick said, "Near as I can tell, Sapphire really likes our Mary."

Cyndy gave Rick a sharp look. 

Hec asked. "Who's the toughest guy in the movies you can think of, Cyndy?" 

"Hoss?"

I nodded. "The best fruit is not what falls, but what you have to reach for."

Cyndy gave me a worried look. 

Rick laughed. "Dan Blocker's a good answer, and something of a local, but not the one Hec was thinking of."

"Clint Eastwood?" 

I laughed. "A man's got to know his limitations."

Cyndy expression shifted to puzzlement. "I don't understand."

I said, "Lookin' back is a bad habit."

(For what it's worth, I probably would not have known any of these quotes. Well, maybe the Dan Blocker quote. I didn't have that much interest in movies. But you already know that Joe and I are not the same person.) 

She still looked puzzled. After a few moments of thought, she said, "John Wayne?"

Rick smirked. "Do you know what his real name is?"

She looked from Rick to Hec to me.  

"Rick heard about it from his mother," I explained, "and looked it up in the school library. Then he told everybody about it when I was getting teased about my first name at Sam Houston."

"So," she stalled while she thought. "John Wayne's real name is," she paused again, still looking puzzled. "Marion?"

Rick nodded. "Marion Robert Morrison."

Chuck volunteered from his table, "So Rick is the only person that gets to use Joe's first name." 

(Chuck also attended Sam Houston Elementary. The name of that school, at least, has not changed. I understand that the school has been designated AVID now, however, and I'm not sure what to think of that.) 

I gave Chuck a thumbs-up and Cyndy a lopsided smile and added, "Not that I'm mean about it or anything. I just may not answer."

The bell rang, and Mr. Mori stood up. 

"Before we dig into the promised discussion of the 6502's indexing modes, there's something I'd like you all to consider." 

He put a transparency on the overhead projector and turned it on.  

"I'm kind of hoping this looks familiar from last week."

We all thought about it for a few moments, and Cyndy suggested, "It looks kind of like the CPU and memory?"

"What is like the CPU and memory?"

Hec spoke up, "I think I get it, too. Kind of like in the same way the CPU interfaces with RAM, the ALU interfaces with registers."

"So what are we looking at?"

Rick said, "It's a partial diagram of the inside of a CPU." 

"You say that with confidence."

Rick glanced back at me and I gave him a thumbs-up. 

"Yeah."

"That's what I want everyone to see. Registers are like very fast RAM, inside the CPU chip. Usually. Except the 9900's working registers. But I've left out the control signals and the control unit. Let's add those." He swapped transparencies.

 

"Any impressions of that that anyone wants to bring up?"

Bob said, "Well, something's got to tell the ALU and the registers what to do, so they call it a control unit?"

"Anything else?"

Bill said, "The control unit also controls the data paths between the registers and the ALU. That's the buffers?"

"Good. Now the ALU handles ordinary math, what handles the addresses?"

Karl said, "Why can't the ALU handle addresses?"

Ted said, "It can, but in some CPUs there's a separate address unit to speed things up."

"Good comments, both of you." 

Mr. Mori swapped transparencies again.


"Some CPUs have a separate address unit. So, Joe, what do you think this diagram is missing?"

"Something needs to interface between the CPU and memory and I/O," I responded.

"What are those called?"

Bill replied for me. "Aren't those the data and address buffers?" 

"Good." 

Scott said, "And it's also missing the instruction pointer."

"Why is that important, Scott?"

"It doesn't show how we know what the current instruction is, or how we get immediate data from instructions into either the ALU or the address unit."

"Great."

(Dang, these guys are sharp. I wish I'd know them when I was in high school in your reality.) 

"I don't want to design a CPU in class with everyone today, so I'm not going to add those to this diagram. Today. Anyway, I hope you'll be able to visualize what's going on in the CPU a little better with these."

"One more thing I want to do before we move on to the 6502 is review what we've seen of register indirect mode and indexing. Who remembers from last week what register indirect mode is?" 

No response.

"Still shifting gears?" 

Pete raised a hesitant hand. 

"Pete?" 

"In register indirect, a CPU register points to the memory location for the instruction's operand." 

"Thank you, Mr. Higgs." Mr. Mori put a transparency from the previous lesson back up. 

  

"We looked at the 9900 pointing to its workspace in RAM with the W register, and then we looked at its ability to point to general locations using any 16-bit register. Almost any. And the working registers are actually already in memory, not in the CPU."

Frank spoke up. "Why doesn't the 9900 have the registers cached internally?" 

Mr. Mori gave him a knowing smirk. "Greedy, aren't we?"

"Is microprocessor technology so far behind?" 

"Every semiconductor manufacturer building microprocessors is pushing the edges of their manufacturing technology. When they design a CPU, they have to make a bet on how many transistors they can squeeze into one chip without running into power problems or reactance and crossfeed issues or even just plain dust problems."

"It doesn't seem like it should be that hard."

"Maybe when you get through college you can get a job with TI and show them how."

Frank laughed. "Okay, okay. Maybe I am too impatient. Maybe they won't have that solved by the time I finish college."

Bob said, "Cache?"

I said, "Cache is fast memory, where you put the data you need quickly."

"Isn't that what internal registers are anyway?"

Mr. Mori said, "We will need to actually discuss this in detail, but, with most CPUs, you have to explicitly bring data into the registers, and if you need what was there before, you have to save it first. The 9900 avoids the saving and restoring steps by keeping the registers in memory anyway, but that makes the working registers slower than internal registers. I think what Frank wants is for the CPU to manage the saving and restoring automatically, so that the registers can be fast and the programmer doesn't have to think about it."

"Yeah. That's what I'm thinking."

"It's an interesting goal."

"I'll keep that in mind."

Mr. Mori nodded. "Back to the register indirect addressing, does the 8080 have such a thing?"

Barry responded, reading from his notes. "H and L can be used as a pair to point to memory."

Scott added, "B:C and D:E can also point to memory for some instructions."

Mr. Mori blinked. "Scott, you've been reading your dad's manuals at home."

Scott grinned.

Mr. Mori chuckled. "Barry and Scott are both correct, and we'll look at the specifics later.

"What's the difference?" Karl asked. 

Scott replied, "I'm not positive, but I think the only instructions I saw that use B:C and D:E for pointing to memory are data moves."

"And we will look at those closer later on, but that's what I understand." Mr. Mori nodded. "How about the 1802?"

Hec and Cyndy both started to reply at the same time,

"Pretty much, ..."

"You said, ..." 

And then they stopped speaking, looking at each other and laughing.

"You first," Hec said.

Cyndy gave him a lopsided smile. "Okay. She turned to Mr. Mori. "You said yesterday, pretty much any of the sixteen registers can point to memory." 

Mr. Mori continued nodding. "What about the 6800?"

Rick and I looked at each other.

Bill spoke up. "X is used as an index register with zero offset for register indirect."

Rick and I both turned and gave Bill a thumbs-up.

"Great." Mr. Mori nodded. "I think we're all paying attention. What does anyone remember about the 6502 from last week?"

Harvey raised his hand, "X and Y are only 8 bits wide."

"Excellent. What does that imply about X and Y being used as index registers?"

Harvey hesitated, then said, "Does that mean they can only point directly into page zero?" 

Mark grumbled, "Just about have to."

Pete said, "What if the 6502 allows a 16-bit constant base?"

Mr. Mori turned to him and said, "You're getting ahead of me."

"Sorry."

"Not a problem." Mr. Mori grinned. "In fact, that's one of the things we promised to talk about today. We'll get there shortly. So," he paused. "How many of you remember the indexing mode of the 9900 from last week, how it differs from the register indirect mode?" 

Frank read from his notes, "The constant in the instruction plus index register contents is the operand address. If the constant is the base address of an array, the register can index the array, and --"

Mr. Mori interrupted him. "Good. Meaning?"He swapped the transparency on the overhead projector.

"We know where the array is, and the register is used to pick the element of the array that we want. The address of the element we're accessing is the constant base address plus the offset into the array."

"Are we all okay for that?"

There were no complaints.

"Pete, since Frank told us one way to interpret this, you tell us the other."   Again he swapped transparencies.

Pete hesitated, then said, "Sometimes you have a lot of arrays that have the same form, and you want to access the same part of each. So the constant part is going to be offset that doesn't change, and the index register will point to the address of the base of the array that you want to look at. The sum still points to the byte you want to access."

"Excellent, again." 

"But if we are talking about strings like that," Pete continued, "before we look at the third letter, we're going to want to check the length byte at offset zero to be sure there is a third letter."

Professor Mori beamed. "Very excellent. I'm going to give everyone who didn't quite follow that a half a minute to think about it."

Bob asked, "How do we check that?"

I volunteered, "Each processor has an instruction to compare a byte with a known value, so you would probably load the count and compare it to the length you want to check."

"Then what?" Mr. Mori asked.

Hec answered, "If it's too small, jump out to do something else."

"Good. And we'll talk more about that later. Now, Joe, what happens when you don't know in advance either which array you're going to be accessing or which element?"

"You mean, neither is constant?" I asked.

"Right." 

"Is there an addressing mode for the 9900 that adds two registers to get the operand address?" I asked.

"Well, actually, no."

(It would be about a year and a half in your reality before Motorola officially announced the 6809, which included such modes by combining the address in an index register with on offset in an accumulator. And about a half a year later, as the 6809 was beginning to ship samples, Motorola would formally announce another new processor, the 68000, which also included such a mode, being able to form an effective address by temporarily adding either a data register or an address register to an address register. And several years after that, Motorola would announce the 68020 with addressing modes that were just way too rich for most programmers to understand. 

Intel would announce the 8086 about the same time Motorola announced the 6809, and the 8086 would include something that kind of looked like this but wasn't, which they called segmented addressing. I objected to their terminology when I studied the 8086 sometime later. But that's all in your timeline. On the other hand, ... but I'm getting way ahead of myself.)

Cyndy spoke before I could. "Then you just use one instruction to add the address and the offset in registers and use the sum in the register in a register indirect mode instruction. It'll require two instructions and leave the target address in a register."

"Hey. That's what I was going to say." I complained, jokingly.

She turned around and lifted her hand with a grin, and we slapped palms.

Mr. Mori nodded with a wry smile, and said, "How many of you didn't follow that?"

Nobody raised a hand.

"I don't believe you all understood it, so I'll ask how many did follow it and are willing to try to explain it at the whiteboard?"

Several of us raised our hands. 

"Ted?" Mr. Mori held up a marker.

Ted stood up and took the marker and, referring back to the transparency, drew the following on the whiteboard while he explained: 

"The address of the array is in the register we're calling Rb. That's any of the sixteen registers."

Mr. Mori nodded. "Well, there are some registers you might not want to use, but, yeah. So, for now we can assume more-or-less any but R0. Do you have a manual at home?"

"Yeah."

"Cool. I might want you to bring it to class sometimes, if it's okay with your dad."

"I think I could. Dad didn't say anything about a non-disclosure agreement."

"Great." 

"The array is a string in this example, a character string, right?" Ted paused. "But I decided the offset is going to be a four this time." 

Mr. Mori interrupted. "Why is that?"

"Just to emphasize that it's in a register and not a constant in the instruction stream."

"Thank you for thinking of that."

Ted continued, "And I'm calling the register that the offset is in Rx, because we don't need to know which it's going to be in -- saying X for index. So we use an add instruction to add the offset to the base, and the sum ends up in Rb." 

He stopped and thought. "Maybe I didn't want to do that."

"Maybe not, but we'll go with that for now. The point is that the CPU has executed one instruction, and the value of one or the other register has been altered, right?"

"Right. After the add instruction, the result in Rb is N plus four, so it's pointing to the letter 'i'." 

"Very good."

"But, as I said, I realized while I was explaining it that now Rb is no longer pointing to the beginning of the name, and that may not be what I wanted. It would also work to add Rb to Rx, instead, wouldn't it?"

"Why would you want to do that?"

"To leave Rb pointing to the base of the array for later math, and maybe to allow bumping Rx up and down from where the index is left pointing." 

"Yeah, that would work, if I understand what I've read about the 9900 correctly. And, while you can always point back by subtracting four, I think your instinct to leave Rb pointing to the base is good. It would be less confusing to leave the base address in Rb, as you say. Very astute."

Cyndy raised her hand. "So we could do the constant offset or constant base this way, too?"

 Mr. Mori pursed his lips and furrowed his brow. "Yes, if you load the constant into register Rx, you can add them explicitly, and have the effective address in a register. And we probably want to know about this when we talk about certain CPUs in more detail. But constant plus index happens a lot, so the indexed mode makes a useful quick shortcut. But, yes, we could do it all in registers with extra instructions if we need to."

She nodded. 

Hec said, "But won't that take more time, since you have to fetch instructions and do explicit math that the address unit could be doing in parallel?"  He looked at Cyndy. "Uhm, although it does leave you with the target address in a register, if you need to use it again."

Cyndy gave him a tight smile and a slow blink.

"Sorry," he said.

"No problem."

Karl piped up. "Somebody's in trouble tonight."

Cyndy turned to him and blinked again. "Whatever do you mean?"

Mr. Mori said, not quite suppressing a smile, "I do appreciate it when you settle your differences outside of class, guys." 

Most of the other boys laughed. Rick and I suppressed our grins. Cyndy smiled knowingly at no one in particular.

Hec reached a raised, hesitant palm to Cyndy, and she touched palms with him, lightly. 

Mr. Mori said, "Cyndy and Hec are pointing out something important here, and it's why I wanted to show you that some CPUs have a somewhat independent address unit. File that away in your brains and we'll come back to it."

He gave us a moment to think.

"Okay, Scott, can you tell us how to do any of this kind of indexing on the 8080?"

Scott shook his head. Then, after a moment's thought, he said, "Wait, maybe put the base address in D:E so we can keep the base, and the offset in H:L, and add, D:E to H:L?"

Mr. Mori nodded. "You think your dad would let you bring his manual to class?"

"He usually keeps it in his office, but I could ask."

"That might be nice. I think you're right. As far as I know, there's no constant offset plus index addressing mode on the 8080, so, whether we have constant offsets or variable offsets, we have to explicitly add them in registers to get the target addresses." He paused.

"I've heard that some engineers from Intel have left and formed a company called Zilog that has announced an 8080-compatible processor, called the Z-80, that does have indexed mode addressing, but I haven't seen a lot of information on it yet."

Bill volunteered, "Kind of like the engineers who left Motorola to make the 6502?" 

"Well, Chuck Peddle and his group didn't have as much financial backing when they left Motorola, so, instead of forming their own company, they took their ideas to MOS Technology -- which was a company that already existed. Similar but different."

He waited for us to shift gears before continuing. "But the 8080 does have instructions to help with this. Can you tell us what they are, Scott?"

"I can't keep them in my head."

"I can't either. So far I'm just working from code snippets I've found in magazine articles. I'm not sure I should show you this diagram, because it might be wrong, but let's see what I think the constant base case might look like."

Mr. Mori swapped the transparency on the projector out.


"You can see that it takes one instruction, L-X-I, to load the constant base and another, D-A-D, to add the base to the offset to get what we want. This is what Cyndy was talking about when she asked about adding the base and offset in registers." 

Again, he waited for us to think about things. "Scott, do you think you can show us the constant offset case from this?"

"Oh, sure." Scott stood and went up to the whiteboard, borrowing the marker from Mr. Mori.

"Hardly anything to change," he said and started copying from the transparency. "The DAD for the addition can be the same. But the constant we are going to load will be the offset, not the base, and we will probably load it into H:L to leave the base address alone." He continued working on the diagram in silence for a short bit, and then announced, "That should do it."

"Load the constant offset into H:L, leave the base address in D:E alone, and that's that."

"Thanks. Now, Barry, can you modify this for the general case, with variable base in D:E and variable constant in H:L?"

Scott turned towards Barry and raised the marker and eraser in his hands.

Barry stood and took the marker and eraser from Scott and went to the board. He studied the diagram for a moment, erased one instruction and moved those after it up. 

"Yep. I think that's it. Wait, I should edit the offset to match the 9900 example. And fix some comments."

  

"Looks pretty cool, doesn't it?" Mr. Mori said. But I should warn you all, things get a little messy when the base and offset aren't already in the right registers. Thank you Barry."

Barry put the marker and eraser on the white board tray and sat down. 

Mr. Mori frowned, and then asked, "Can anyone talk about how this works on the 1802?"

None of us volunteered.

"Bob? Chuck? Mark? Bill?" 

They all shook their heads, so he turned toward our table. "Hec?"

"Ask me next week."

"Hey, what?"

"Rick and Joe were saying the OC library has 1802 docs, so we're planning on going to take a look at them this weekend." 

"Oh. Cool. Maybe I can get them to let me take a look at them, too."

Chuck said, "If you need somebody to get you in, I could meet you there."

Mr. Mori blinked. "That would be great. Let's talk about that after class." 

"Just a guess," I offered. "On the 1802 are we going to have to do the address math a byte at a time, and then use the X register to switch the register that has the result address to the current index?"

"That's a good guess, from what I understand. Any body not get an idea what that looks like?" 

Mark said, "I think we're all pretty vague on it."

"Let's wait to draw pictures until I can get a look at an actual manual. For now, let's ask Joe and Rick how this is going to look on the 6800." 

"You never drew us any pictures of this yesterday," Rick complained as he turned to me.

"Give it a shot, Stant," I said 

"Can I be lazy and just point out that it looks more or less like the 9900 for the, uhm," he looked at his notes, "constant offset in a string case," he looked at me and then Chuck for confirmation.

We both nodded.

"And if the array is in the first 256 bytes of memory, you can use the constant base plus register index form for that, too," he checked with me again.

I nodded.

"And then I can just draw the one Joe just did at the library where both the array base and the offset are not known until the program starts running?" He looked at Mr. Mori.

Mr. Mori pursed his lips, nodding. "Why that one only?"

"Because it's going to take more instructions to do the addition," Rick trailed off. Then he said, "Maybe we should just draw them all."

Mr. Mori grinned. "I'll leave that up to you guys."

"You do the constant base, Joe."

"Sure, give me that one. How about you grab the data sheet?" I picked up my notes from the library and went to the board and started erasing. Rick went to the pile of documents at the front of the room and found the 6800 data sheet.

We looked through the instructions and at my notes.

Rick said, "Can we see the one from the 9900 again?"

"Sure." Mr. Mori put the transparency on the projector.

Rick pointed at he instruction list from the 9900 example project on the white board, and I nodded and sketched the constant base case out on the board. 


"The main difference between the 9900 and the 6800 here is that the array has to start in the first 256 bytes of the address space," I explained. 

I stopped and thought a minute. "And I guess I want to point out that, where on the 8080 diagrams, we were calling the instruction of interest op code C, that was after the address calculation , on the 9900 and in this diagram, the instruction of interest is op-code B, and op-code C is already the next instruction. Everything happens in one instruction."

Mr. Mori nodded. "You say the array has to start in the first 256 bytes. How about the test score? Does the array have to all fit within the first 256 bytes of memory?"

I scratched my head while I thought. "If we are doing something other than bumping the pointer in X up and down a little, the address math might get complicated, but X is 16 bits wide, so I'd guess not." 

"I think that's correct." 

"Your turn, Rick." I handed the marker and eraser to him. 

Instead of modifying my diagram, Rick first pointed to the short op-code list.

"Just to recap about the instructions, 6800 instructions are variable length, aren't they Joe?" Rick asked.

"Yeah," I replied.

"So the byte at 1017 is the last byte of instruction op code A."

"Yep."

"Op code B at 1018 is the indexed mode op-code byte, and the constant that follows it at 1019 is the base address, which is limited to between 0 and 256."

"Right."

"And the next op-code, op-code C, starts at 1020."

"Mmm hmm." 

"Got it." Rick started modifying the diagram. "Now, this time, the base address is going to be in X, and it's going to be a full 16-bit address. And we're probably going to want to test the length byte at offset zero first, but we haven't been showing that, so we won't do that in this diagram."

"Fair enough," Mr. Mori commented.

"Pretty much the same as the 9900, again." 

"And this works as long as the array is smaller than 256 bytes."

"Right." 

"I assume that it's the address unit that generates the address from the index register and the constant in the instruction," Rick added. 

"Very good," Mr. Mori said. 

Rick looked at me and held up the marker.

I grinned.

He said, "You were the one writing something like this in the library."

"Dang, but I'm a pushover," I complained as I took the marker and eraser and turned to the board and looked at the diagram, trying to plan out where to add all the extra instructions. 

"In the library," I said, "we worked out some steps to add B to X. But that only works for 256-byte offsets."

"Do you have that?" Mr. Mori asked.

Rick picked up my notes and waved them.

Mr. Mori said, "Let's take a look at it." 

"What did we call the place in memory to work on the index?" I asked.

"You called it X16." He showed me the page.

"Okay" I erased everything but the string. "We can put X16 in the direct page to save cycles and op-code bytes, because the direct page mode only needs one byte of address." I drew the bytes for X16 on the board where I thought they would be out of the way. "To do that, X16 has to be at an address below 255."

"Below 255, not at 255?" Mr. Mori asked.

"X16 takes two bytes, and we need both bytes to be addressable in direct page mode."

"Good." 

"At the start of the code, X will be pointing to the beginning of the name. B will have the offset, and we'll assume that's 4, like Ted did." I drew in register X before and after, and drew B with a 4 in it, and looked around at Ted, who gave me a thumbs-up.

Then I looked back at the notes Rick was holding for me. "And after we add the offset, X will point to the 'i', of course. And it's going to be easier to show you the actual instructions than wave my hands at them."

I diagrammed a piece of memory starting at 1017. "Last byte of the preceding op-code."

I filled in the direct page store X instruction, using the mnemonic.

"Okay, Rick, what was next?"

"ADD accumulator B to the low byte of X16."

"Since the 6800 is most significant byte first, the low byte is at X16 plus one."

I paused to examine the diagram on the board.

"Next thing you did was load accumulator A from the high byte."

"The load instruction on the 6800 doesn't affect the carry flag. Does the store?" I asked.

Rick picked the data sheet back up and scanned it. "Nope."

"I think we could store B first and then we wouldn't have to use A."

"You might be right. Wish we had some way to check."

"Me, too." I wrote in the store instruction. 

"Me three," echoed Mr. Mori. 

A number of us chuckled.

"So we load the high byte at X16 into B." I wrote that into the diagram. "And, Rick, you were the one that pointed out we could just use the add carry instruction in the immediate mode to add zero to B, and get the carry added in." I added that to the diagram.

Mr. Mori said, "Wait, slow down and say that again."

Rick explained. "We want to add the carry to the high byte. But we don't have anything else to add besides the carry. There's no single special instruction that we know of to just add the carry in without adding something else."

 "I see."

"Adding a constant zero wouldn't usually make a lot of sense, but if it's the add with carry instruction, it does the trick." 

"Very good." 

"And Rick was the one who figured that out," I said. "Then we store the updated high byte from B in," I ran out of space at the bottom of the whiteboard and moved over to continue writing op-codes. "And load the result into X and we're finally pointing to the byte we want." 

"That's a lot of work," Karl complained.

"That's what Rick and I were thinking. But we didn't find any instruction to directly add an accumulator to X or to add sixteen bits at once." 

(Spoiler: Motorola would announce a single-chip micro-controller CPU called the 6801 sometime during the next year in your timeline, which would be an extension of the 6800 that had both the add B to X instruction and 16-bit math. It would not have all the capabilities of the 6809, but it would be a significant improvement.)

"Joe decided not to diagram the steps to add the two bytes. 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 I don't mind. Please take over."

There were scattered chuckles. 

"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. Joe is going to read the instructions, and Rick is going to tell us what happens to each byte."

"Why does Joe get the easy job?" Rick complained with a grin.

More chuckles. 

"Scott, you're direct page memory location X16."

Scott stood up. "What do I do?"

"Mostly remember your current value and tell us what it is."

"I guess I can do that." 

"But we need an actual, concrete example address. Rick, what's the actual address?"

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

"Ten it is. Scott, you're location ten. 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 when the code starts?" 

"N."

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

Karl looked at Rick.

"You pick," Rick said. 

"Anything less than 65,536?" Karl asked.

"What do you say, Joe?" Mr. Mori asked.

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

"How about 31,999?"

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

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

"Well, 32,000 divided by 256," He looked at Mr. Mori, who nodded. He continued, "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," Mr. Mori explained. "What do you have?"

Barry said, "Something random?"

"Probably."

"Okay, I have seventeen."

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

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

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

"Yeah."

"Then I'll say there'll be no carry to start." 

"Okay, Joe, read the instructions."

"Store X at location ten."

Karl said, "Scott first?"

Rick said, "Yeah. Scott gets the most significant byte."

Karl said, "Scott gets one twenty-four." 

Scott said, "124."

Rick continued, "And Barry gets the least significant byte." 

"Barry gets two fifty-five," Karl said.

Barry said, "255."

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

Rick said, "We need the value in location eleven to store in a temporary buffer?"

Mr. Mori nodded. 

Barry said, "255."

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

Bob said, "Three." 

Mark said, "Carry." 

I continued, "Store B to location eleven." 

Rick said, "What Joe said." 

Bob said, "Three."

Barry said, "Three."

Mark said, "Carry unaffected?"

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

Rick said, "Ditto." 

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."

Rick said, "Constant zero read from the next byte of instruction and store in buffer." 

Mark said, "We still have carry."

Rick said, "Adding the buffer and the carry to B results in one twenty-five." 

Bob said, "One twenty-five."

Mark said, "Now no carry."

I said, "Store B in location ten."

Rick said, "The data just moves." 

Bob said, "One twenty-five."

Scott said, "One twenty-five."

Mark said, "Carry unaffected, no carry."

I said, "Load X from location ten."

Rick said, "High byte from location ten." 

Scott said, "124."

Karl said, "I have to hold that 124 in half of me?"

Mr. Mori nodded. "Or maybe there is an intermediate buffer. One or the other."

Rick said, "Low byte from location eleven." 

Barry said, "3."

Karl said, "Man this gets boring." 

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

We all laughed.

Karl grinned. "Well, anyway, with three in my low half and 124 in my high half, X is now 32,003. Does this get recalculated or just marked valid?"

Mr. Mori said, "At the end of the instruction clock cycle, it's assumed to be valid."

"Just assumed?" Karl checked.

"Just assumed. If there are no errors in the electronics, it has to be valid."

"Okay." 

I said, "And we are finally ready to do whatever op-code C was. But the instruction will be in indexed mode, and the index byte will be 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.

"Wait. Joe, Rick, I still need your help."

"What?" Rick started.

I said, "Oh. What if we have more than eight bits to add to X, right?"

"Right."

Rick and I stood up to look at the whiteboard, and Rick said, "If we start with the sixteen bits to add in A and B as a pair, we're already almost there with this."

I blinked, and said, "I think you're right."

"Combine two instructions into one," Rick went to the whiteboard and started writing the instruction sequence in a clear space.

 opa (whatever it was)
 STX X16 (2 bytes)
 ADDB X16+1 (2 bytes)
 STAB X16+1 (2 bytes)
 ADCA X16 (2 bytes -- instead of LDAA X16; ADCA #0)
 STAA X16 (2 bytes)
 LDX X16 (2 bytes)
 opc 0,X (2 bytes)

"The add with carry to A from X16 is instead of load A from X16 and add with carry immediate zero. Could we put a return on the end of that?" Rick asked.

"Depends on what op-code A is, perhaps," Mr. Mori replied. "But I don't see a likely problem with that. Anybody see a problem with that?"

Nobody said they saw a problem with it. 

"Okay, let's take a break." 

TOC
Next
Where it starts

Copyright 2026 Joel Matthew Rees




[Edit record here:  https://joelrees-novels.blogspot.com/2026/07/mark00-3809-2801-alus-register-indirect-role-playing-6800.html]


[MARK00] 3809/2801: ALUs, Register Indirect Review, Role Playing the 6800

EDIT MARK record 00
Read the current version at: 
https://joelrees-novels.blogspot.com/2026/07/3809-2801-alus-register-indirect-role-playing-6800.html

2801
ALUs, Register Indirect Review,
Role Playing the 6800

Motorola M6800 EXORcises
TOC

When we walked into the southeast wing from the entrance closest to the Permian student parking, Hec, Cyndy, and Sapphire were talking in the hall outside the electronics lab.

"There she is, Mary."

I glanced aside at Rick with a raised eyebrow before raising my left hand. "Greetings, earthlings," I said as we approached.

Hec cocked his head sideways, and Cyndy gave me an eye-roll.

Sapphire gave me a sour moue. "Hah. You only think you are of a superior race," she jested, before reaching out for my hand. I gave her hand a squeeze before we both dropped our hands a little guiltily.

Rick laughed. "Nope. Nothing to see here, folks." 

Sapphire gave him a look of mock innocent perplexity.

He just grinned. 

"How was calculus?" she asked.

"No class today, we just studied in the library," Rick answered. "Found some microprocessor manuals. They have the 1802 manual, too, Hec."

"You didn't check it out for me?"

"The manuals are all in the reference section," I explained.

"So you can't check any of them out," Cyndy said, somewhat wistfully.

"We could meet at the library, I think," Rick suggested. "Although the only time after school I'll be able to do that will be Friday or Saturday evening. Or Sunday."

"Do you guys have a game Saturday?" I asked. 

"Friday," Sapphire answered. "Which raises a question. Will you and Rick will be with us at the games?" 

Rick and I looked at each other. 

"I'm going to have to think about this," Rick said.

I nodded. "I think I'm game for it, but maybe not every game. You're not asking Hec. I guess he's committed?" 

"I'm like you, not every game," Hec replied. "But I'm a student here."

"Which raises a question," Rick pointed out. "Are there going to be riots on the field or in the schools if OHS students are dancing with the Permian cheer dance team at game time?"

I grimaced. "You could have talked all day, ..."

"But somebody has to ask," Cyndy finished for me. 

We all stood in silence for a moment or two.

I spoke up. "I guess I was hoping Ms. Michaels would run that question past the school staff."

Sapphire said, "Well, yeah. Ms. Michaels wants to know what you and Rick are thinking before she starts a discussion."

Rick looked at me and I nodded. 

"So, not this Friday," I said. "I'm not sure we're going to that much up to speed anyway."

"Sapphire, you need to get to class," Cyndy reminded her.

"True. We'll talk later?"

Rick and I nodded.

Sapphire touched fingers with Cyndy and reached out to me. I met her hand with mine and we gave each other's hands another squeeze, and she left. The four of us entered the classroom.

As we sat down, Hec asked, "What happened between you two last night?"

"We just studied and talked," I replied.

Rick said, "Near as I can tell, Sapphire really likes our Mary."

Cyndy gave Rick a sharp look. 

Hec asked. "Who's the toughest guy in the movies you can think of, Cyndy?" 

"Hoss?"

I nodded. "The best fruit is not what falls, but what you have to reach for." 

Rick laughed. "Dan Blocker's a good answer, and something of a local, but not the one Hec was thinking of."

"Clint Eastwood?" 

I laughed. "A man's got to know his limitations."

"I don't understand."

I said, "Lookin' back is a bad habit."

(For what it's worth, I probably would not have known any of these quotes. Well, maybe the Dan Blocker quote. I didn't have that much interest in movies. But you already know that Joe and I are not the same person.) 

She still looked puzzled. After a few moments of thought, she said, "John Wayne?"

Rick smirked. "Do you know what his real name is?"

She looked from Rick to Hec to me.  

"Rick heard about it from his mother," I explained, "and looked it up in the school library. Then he told everybody about it when I was getting teased about my first name at Sam Houston."

"So," she thought. "His real name is," she paused again, still looking puzzled. "Marion?"

Rick nodded. "Marion Robert Morrison."

Chuck volunteered from his table, "So Rick is the only person that gets to use Joe's first name." 

(Chuck also attended Sam Houston Elementary. The name of that school, at least, has not changed. I understand that the school has been designated AVID now, however, and I'm not what to think of that.) 

I gave Chuck a thumb-up and Cyndy a lopsided smile and added, "Not that I'm mean about it or anything. I just may not answer."

The bell rang, and Mr. Mori stood up. 

"Before we dig into the promised discussion of the 6502's indexing modes, there's something I'd like you all to consider." 

He put a transparency on the overhead projector and turned it on.  

"I'm kind of hoping this looks familiar from last week."

We all thought about it for a few moments, and Cyndy suggested, "It looks kind of like the CPU and memory?"

"What is like the CPU and memory?"

Hec spoke up, "I think I get it, too. Kind of like in the same way the CPU interfaces with RAM, the ALU interfaces with registers."

"So what are we looking at?"

Rick said, "It's a partial diagram of the inside of a CPU." 

"You say that with confidence."

Rick glanced back at me and I gave him a thumbs-up. 

"Yeah."

"That's what I want everyone to see. Registers are like very fast RAM, inside the CPU chip. Usually. I've left out the control signals and the control unit. Let's add those." He swapped transparencies.

 

"Any impressions of that that anyone wants to bring up?"

Bob said, "Well, something's got to tell the ALU and the registers what to do, so they call it a control unit?"

"Anything else?"

Bill said, "The control unit also controls the data paths between the registers and the ALU. That's the buffers?"

"Good. Now the ALU handles ordinary math, what handles the addresses?"

Karl said, "Why can't the ALU handle addresses?"

Ted said, "It can, but in some CPUs there's a separate address unit to speed things up."

"Good comments, both of you." 

Mr. Mori swapped transparencies again.


"Some CPUs have a separate address unit. So, Joe, what do you think this diagram is missing?"

"Something needs to interface between the CPU and memory and I/O," I responded.

"What are those called?"

Bill replied for me. "Aren't those the data and address buffers?" 

"Good." 

Scott said, "And it's also missing the instruction pointer."

"Why is that important, Scott?"

"It doesn't show how we get immediate data from instructions into either the ALU or the address unit."

"Great."

(Dang, these guys are sharp. I wish I'd know them when I was in high school in your reality.) 

"I don't want to design a CPU in class with everyone today, so I'm not going to add those to this diagram. Today. Anyway, I hope you'll be able to visualize what's going on in the CPU a little better with these."

"One more thing I want to do before we move on to the 6502 is review what we've seen of register indirect mode and indexing. Who remembers from last week what register indirect mode is?" 

No response.

"Still shifting gears?" 

Pete raised a hesitant hand. 

"Pete?" 

"A CPU register points to the memory location for the instruction's operand." 

"Thank you, Mr. Higgs." Mr. Mori put a transparency from the previous lesson back up. 

  

"We looked at the 9900 pointing to its workspace in RAM with the W register, and then we looked at its ability to point to general locations using any 16-bit register. Does the 8080 have this kind of addressing?"

Barry responded, reading from his notes. "H and L can be used as a pair to point to memory."

Scott added, "B:C and D:E can also point to memory for some instructions."

Mr. Mori blinked. "Scott, you've been reading your dad's manuals at home."

Scott grinned.

Mr. Mori chuckled. "Barry and Scott are both correct, and we'll look at the specifics later.

"What's the difference?" Karl asked. 

Scott replied, "I'm not positive, but I think the only instructions I saw that use B:C and D:E for pointing to memory are data moves."

"And we will look at those closer later on, but that's what I understand." Mr. Mori nodded. "How about the 1802?"

Hec and Cyndy both started to reply at the same time,

"Pretty much, ..."

"You said, ..." 

And then they stopped speaking, looking at each other and laughing.

"You first," Hec said.

Cyndy gave him a lopsided smile. "Okay. She turned to Mr. Mori. "You said yesterday, pretty much any of the sixteen registers can point to memory." 

Mr. Mori continued nodding. "What about the 6800?"

Rick and I looked at each other.

Bill spoke up. "X is used as an index register with zero offset for register indirect."

Rick and I both turned and gave Bill a thumbs-up.

"Great." Mr. Mori nodded. "I think we're all paying attention. What does anyone remember about the 6502 from last week?"

Harvey raised his hand, "X and Y are only 8 bits wide."

"Excellent. What does that imply about X and Y being used as index registers?"

Harvey hesitated, then said, "Does that mean they can only point directly into page zero?" 

Mark grumbled, "Just about have to."

Pete said, "What if the 6502 allows a 16-bit constant base?"

Mr. Mori turned to him and said, "You're getting ahead of me."

"Sorry."

"Not a problem." Mr. Mori grinned. "In fact, that's one of the things we promised to talk about today. So," he paused. "How many of you remember the indexing mode of the 9900 from last week, how it differs from the register indirect mode?" 

Frank read from his notes, "The constant in the instruction plus index register contents is the operand address. If the constant is the base address of an array, the register can index the array, and --"

Mr. Mori interrupted him. "Good. Meaning?"He swapped the transparency on the overhead projector.

"We know where the array is, and the register is used to pick the element of the array that we want. The address of the element we're accessing is the constant base address plus the offset into the array."

"Are we all okay for that?"

There were no complaints.

"Pete, since Frank told us one way to interpret this, you tell us the other."   Again he swapped transparencies.

Pete hesitated, then said, "Sometimes you have a lot of arrays that have the same form, and you want to access the same part of each. So the constant part is going to be offset that doesn't change, and the index register will point to the address of the base of the array that you want to look at. The sum still points to the byte you want to access."

"Excellent, again." 

"But if we are talking about strings like that," Pete continued, "before we look at the third letter, we're going to want to check the length byte at offset zero to be sure there is a third letter."

Professor Mori beamed. "Very excellent. I'm going to give everyone who didn't quite follow that a half a minute to think about it."

Bob asked, "How do we check that?"

I volunteered, "Each processor has an instruction to compare a byte with a known value, so you would probably load the count and compare it to the length you want to check."

"Then what?" Mr. Mori asked.

Hec answered, "If it's too small, jump out to do something else."

"Good. And we'll talk more about that later. Now, Joe, what happens when you don't know in advance either which array you're going to be accessing or which element?"

"You mean, neither is constant?" I asked.

"Right." 

"Is there an addressing mode for the 9900 that adds two registers to get the operand address?" I asked.

"Well, actually, no."

(It would be about a year and a half in your reality before Motorola officially announced the 6809, which included such modes by combining the address in an index register with on offset in an accumulator. And about a half a year later, as the 6809 was beginning to ship samples, Motorola would formally announce another new processor, the 68000, which also included such a mode, being able to form an effective address by temporarily adding either a data register or an address register to an address register. And several years after that, Motorola would announce the 68020 with addressing modes that were just way too rich for most programmers to understand. 

Intel would announce the 8086 about the same time Motorola announced the 6809, and the 8086 would include something that kind of looked like this but wasn't, which they called segmented addressing. I objected to their terminology when I studied the 8086 sometime later. 

But that's all in your timeline. On the other hand, ... but I'm getting way ahead of myself.)

Cyndy spoke before I could. "Then you just use one instruction to add the address and the offset in registers and use the sum in the register in a register indirect mode instruction. It'll require two instructions and leave the target address in a register."

"Hey. That's what I was going to say." I complained, jokingly.

She turned around and lifted her hand with a grin, and we slapped palms.

Mr. Mori nodded with a wry smile, and said, "How many of you didn't follow that?"

Nobody raised a hand.

"I don't believe you all understood it, so I'll ask how many did follow it and are willing to try to explain it at the whiteboard?"

Several of us raised our hands. 

"Ted?" Mr. Mori held up a marker.

Ted stood up and took the marker and, referring back to the transparency, drew the following on the whiteboard while he explained: 

"The address of the array is in the register we're calling Rb. That's any of the sixteen registers but R0."

Mr. Mori nodded. "Well, there are some other registers you might not want to use, but, yeah. So, for now we can assume more-or-less any but R0. Do you have a manual at home?"

"Yeah."

"Cool. I might want you to bring it to class sometimes, if it's okay with your dad."

"I think I could. Dad didn't say anything about a non-disclosure agreement."

"Great." 

"The array is a string in this example, a character string, right?" Ted paused. "But I decided the offset is going to be a four this time." 

Mr. Mori interrupted. "Why is that?"

"Just to emphasize that it's in a register and not a constant in the instruction stream."

"Thank you for thinking of that."

Ted continued, "And I'm calling the register that the offset is in Rx, because we don't need to know which it's going to be in. Saying X for index. So we use an add instruction to add the offset to the base, and the sum ends up in Rb." 

He stopped and thought. "Maybe I didn't want to do that."

"Maybe not, but we'll go with that for now. The point is that the CPU has executed one instruction, and the value of one or the other register has been altered, right?"

"Right. After the add instruction, the result in Rb is N plus four, so it's pointing to the letter 'i'." 

"Very good."

"But, as I said, I realized while I was explaining it that now Rb is no longer pointing to the beginning of the name, and that may not be what I wanted. It would also work to add Rb to Rx, instead, wouldn't it?"

"Why would you want to do that?"

"To leave Rb pointing to the base of the array for later math, and maybe to allow bumping Rx up and down from where the index is left pointing." 

"Yeah, that would work, if I understand what I've read about the 9900 correctly. And, while you can always point back by subtracting four, I think you're instinct to leave Rb pointing to the base is good. It would be less confusing to leave the base address in Rb, as you say. Very astute."

Cyndy raised her hand. "So we could do the constant offset or constant base this way, too?"

 Mr. Mori pursed his lips and furrowed his brow. "Yes, if you load the constant into register Rx, you can add them explicitly, and have the effective address in a register. And we probably want to know that when we talk about certain CPUs in more detail. But constant plus index happens a lot, so the indexed mode makes a useful quick shortcut. But, yes, we could do it all in registers with extra instructions if we need to."

She nodded. 

Hec said, "But won't that take more time, since you have to fetch instructions and do explicit math that the address unit could be doing in parallel?"  He looked at Cyndy. "Uhm, although it does leave you with the target address in a register, if you need to use it again."

Cyndy gave him a tight smile and a slow blink.

"Sorry," he said.

"No problem."

Karl piped up. "Somebody's in trouble tonight."

Cyndy turned to him and blinked again. "Whatever do you mean?"

Mr. Mori said, not quite suppressing a smile, "I do appreciate it when you settle your differences outside of class, guys." 

Most of the other boys laughed. Rick and I suppressed our grins. Cyndy smiled knowingly at no one in particular.

Hec reached a raised, hesitant palm to Cyndy, and she touched palms with him, lightly. 

Mr. Mori said, "Cyndy and Hec are pointing out something important here, and it's why I wanted to show you that some CPUs have a somewhat independent address unit. File that away and we'll come back to it."

He gave us a moment to think.

"Okay, Scott, can you tell us how to do any of this kind of indexing on the 8080?"

Scott shook his head. Then, after a moment's thought, he said, "Wait, maybe put the base address in D:E so we can keep the base, and the offset in H:L, and add, D:E to H:L?"

Mr. Mori nodded. "You think your dad would let you bring his manual to class?"

"He usually keeps it in his office, but I could ask."

"That might be nice. I think you're right. As far as I know, there's no constant offset plus index addressing mode on the 8080, so, whether we have constant offsets or variable offsets, we have to explicitly add them in registers to get the target addresses." He paused.

"I've heard that some engineers from Intel have left and formed a company called Zilog that has announced an 8080-compatible processor, called the Z-80, that does have indexed mode addressing, but I haven't seen a lot of information on it yet."

Bill volunteered, "Kind of like the engineers who left Motorola to make the 6502?" 

"Well, Chuck Peddle and his group didn't have as much financial backing when they left Motorola, so, instead of forming their own company, they took their ideas to MOS Technology -- which was a company that already existed. Similar but different."

He waited for us to shift gears before continuing. "But the 8080 does have instructions to help with this. Can you tell us what they are, Scott?"

"I can't keep them in my head."

"I can't either. And so far I'm just working from code snippets I've found in magazine articles. I'm not sure I should show you this diagram, because it might be wrong, but let's see what I think the constant base case might look like."

Mr. Mori swapped the transparency on the projector out.


"You can see that it takes one instruction, L-X-I, to load the constant base and another, D-A-D, to add the base to the offset to get what we want. This is what Cyndy was talking about when she asked about adding the base and offset in registers." 

Again, he waited for us to think about things. "Scott, do you think you can show us the constant offset case from this?"

"Oh, sure." Scott stood and went up to the whiteboard, borrowing the marker from Mr. Mori.

"Hardly anything to change," he said and started copying from the transparency. "The DAD for the addition can be the same. But the constant we are going to load will be the offset, not the base, and we will probably load it into H:L to leave the base address alone." He continued working on the diagram in silence for a short bit, and then announced, "That should do it."

"Load the constant offset into H:L, leave the base address in D:E alone, and that's that."

"Thanks. Now, Barry, can you modify this for the general case, with variable base in D:E and variable constant in H:L?"

Scott turned towards Barry and raised the marker and eraser in his hands.

Barry stood and took the marker and eraser from Scott and went to the board. He studied the diagram for a moment, erased one instruction and moved those after it up. 

"Yep. I think that's it. Wait, I should edit the offset to match the 9900 example. And fix some comments."

  

"Looks pretty cool, doesn't it?" Mr. Mori said. But I should warn you all, things get a little messy when the base and offset aren't already in the right registers. Thank you Barry."

Barry put the marker and eraser on the white board tray and sat down. 

Mr. Mori frowned, and then asked, "Can anyone talk about how this works on the 1802?"

None of us volunteered.

"Bob? Chuck? Mark? Bill?" 

They all shook their heads, so he turned toward our table. "Hec?"

"Ask me next week."

"Eh, what?"

"Rick and Joe were saying the OC library has 1802 docs, and we're planning on going to take a look at them this weekend." 

"Oh. Cool. Maybe I can get them to let me take a look at them."

Chuck said, "If you need somebody to get you in, I could meet you there."

Mr. Mori blinked. "That would be great. Let's talk about that after class." 

"Just as a guess," I offered, "on the 1802 are we going to have to do the address math a byte at a time, and then use the X register to switch the register that has the result address to the current index?"

"That's a good guess, from what I understand. Any body not get an idea what that looks like?" 

Mark said, "I think we're all pretty vague on it."

"Let's wait to draw pictures until I can get a look at an actual manual. For now, let's ask Joe and Rick how this is going to look on the 6800." 

"You never drew us any pictures of this yesterday," Rick complained as he turned to me.

"Give it a shot, Stant," I said 

"Can I be lazy and just point out that it looks more or less like the 9900 for the, uhm," he looked at his notes, "constant offset in a string case," he looked at me and then Chuck for confirmation.

We both nodded.

"And if the array is in the first 256 bytes of memory, you can use the constant plus register form for that, too," he checked with me again.

I nodded.

"And just draw the one we just did where both the array base and the offset are not known until the program starts running?" He looked at Mr. Mori.

Mr. Mori pursed his lips, nodding. "Why that one only?"

"Because it's going to take more instructions to do the addition," Rick trailed off. Then he said, "Maybe we should just draw them all."

Mr. Mori grinned. "I'll leave that up to you guys."

"You do the constant base, Joe."

"Sure, give me that one. How about you grab the data sheet?" I picked up my notes from the library and went to the board and started erasing. Rick went to the pile of documents at the front of the room and found the 6800 data sheet.

We looked through the instructions and at my notes.

Rick said, "Can we see the one from the 9900 again?"

"Sure." Mr. Mori put the transparency on the projector.

Rick pointed at he instruction list from the 9900 example project on the white board, and I nodded and sketched the constant base case out on the board. 


"The main difference between the 9900 and the 6800 here is that the array has to start in the first 256 bytes of the address space," I explained. 

I stopped and thought a minute. "And I guess I want to point out that, where on the 8080 diagrams, we were calling the instruction of interest op code C, that was after the address calculation , on the 9900 and in this diagram, the instruction of interest is op-code B, and op-code C is already the next instruction. Everything happens in one instruction."

Mr. Mori nodded. "You say the array has to start in the first 256 bytes. How about the test score. Does the array have to all fit within the first 256 bytes of memory?"

I scratched my head while I thought. "If we are doing something other than bumping the pointer in X up and down a little, the address math might get complicated, but X is 16 bits wide, so I'd guess not." 

"I think that's correct." 

"Your turn, Rick." I handed the marker and eraser to him. 

Instead of modifying my diagram, Rick first pointed to the short op-code list.

"Just to recap about the instructions, 6800 instructions are variable length, aren't they Joe?" Rick asked.

"Yeah," I replied.

"So the byte at 1017 is the last byte of instruction op code A."

"Yep."

"Op code B at 1018 is the indexed mode op-code byte, and the constant that follows it at 1019 is the base address, which is limited to between 0 and 256."

"Right."

"And the next op-code, op-code C, starts at 1020."

"Mmm hmm." 

"Got it." Rick started modifying the diagram. "Now, this time, the base address is going to be in X, and it's going to be a full 16-bit address. And we're probably going to want to test the length byte at offset zero first, but we haven't been showing that, so we won't do that in this diagram."

"Fair enough," Mr. Mori commented.

"Pretty much the same as the 9900, again." 

"I assume that it's the address unit that generates the address from the index register and the constant in the instruction," he added. 

"Very good," Mr. Mori said. 

Rick looked at me and held up the marker.

I grinned.

He said, "You were the one writing something like this in the library."

"Dang, but I'm a pushover," I complained as I took the marker and eraser and turned to the board and looked at the diagram, trying to plan out where to add all the extra instructions. 

"In the library," I said, "we worked out some steps to add B to X. But that only works for 256-byte offsets."

"Do you have that?" Mr. Mori asked.

Rick picked up my notes and waved them.

Mr. Mori said, "Let's take a look at it." 

"What did we call the place in memory to work on the index?" I asked.

"You called it X16." He showed me the page.

"Okay" I erased everything but the string. "We can put X16 in the direct page to save cycles and op-code bytes, because the direct page mode only needs one byte of address." I drew the bytes for X16 on the board where I thought they would be out of the way. "To do that, X16 has to be at an address below 255."

"Below 255, not at 255?" Mr. Mori asked.

"X16 takes two bytes, and we need both bytes to be addressable in direct page mode."

"Good." 

"At the start of the code, X will start pointing to the beginning of the name. B will have the offset, and we'll assume that's 4, like Ted did." I drew in register X before and after, and drew B with a 4 in it, and looked around at Ted, who gave me a thumbs-up.

Then I looked back at the notes Rick was holding for me. "And after we add the offset, X will point to the 'i', of course. And it's going to be easier to show you the actual instructions than wave my hands at them."

I diagrammed a piece of memory starting at 1017. "Last byte of the preceding op-code."

I filled in the direct page store X instruction, using the mnemonic.

"Okay, Rick, what was next?"

"ADD accumulator B to the low byte of X16."

"Since the 6800 is most significant byte first, the low byte is at X16 plus one."

I paused to examine the diagram on the board.

"Next thing you did was load accumulator A from the high byte."

"The load instruction on the 6800 doesn't affect the carry flag. Does the store?" I asked.

Rick picked the data sheet back up and scanned it. "Nope."

"I think we could store B first and then we wouldn't have to use A."

"You might be right. Wish we had some way to check."

"Me, too." I wrote in the store instruction. "So we load the high byte at X16 into B." I wrote that into the diagram. "And you were the one that pointed out we could just use the add carry instruction in the immediate mode to add zero to B, and get the carry added in." I added that to the diagram.

Mr. Mori said, "Wait, slow down and say that again."

Rick explained. "We want to add the carry to the high byte. But we don't have anything else to add besides the carry. There's no special instruction that we know of to just add the carry in without adding something else."

 "I see."

"Adding a constant zero wouldn't make a lot of sense, but if it's the add with carry instruction, it does the trick." 

"Very good." 

"Rick was the one who figured that out," I said. "Then we store the updated high byte from B in," I ran out of space at the bottom of the whiteboard and moved over to continue writing op-codes. "And load the result into X and we're finally pointing to the byte we want." 

"That's a lot of work," Karl complained.

"That's what Rick and I were thinking. But we didn't find any instruction to directly add an accumulator to X or to add sixteen bits at once." 

(Spoiler: Motorola would announce a micro-controller CPU called the 6801 sometime during the next year in your timeline, which was an extension of the 6800 that had both the add B to X instruction and 16-bit math.)

"Joe decided not to diagram the steps to add the two bytes. 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 I don't mind. Please take over."

There were scattered chuckles. 

"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. Joe is going to read the instructions, and Rick is going to tell us what happens to each byte."

"Why does Joe get the easy job?" Rick complained with a grin.

More chuckles. 

"Scott, you're direct page memory location X16."

Scott stood up. "What do I do?"

"Mostly remember your current value and tell us what it is."

"I guess I can do that." 

"But we need an actual, concrete example address. Rick, what's the actual address?"

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

"Ten it is. Scott, you're location ten. 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." 

Karl looked at Rick.

"You pick," Rick said. 

"Anything less that 65,536?"

"What do you say, Joe?" Mr. Mori asked.

"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 and low bytes."

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

"Well, 32,000 divided by 256," He looked at Mr. Mori, who nodded. He continued, "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," Mr. Mori explained. "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."

"Then there'll be no carry to start." 

"Okay, Joe, read the instructions."

"Store X at location ten."

Karl said, "Scott first?"

Rick said, "Yeah. Scott gets the most significant byte."

Karl said, "Scott gets one twenty-four." 

Scott said, "124."

Rick continued, "And Barry gets the least significant byte." 

"Barry gets two fifty-five."

Barry said, "255."

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

Rick said, "We need the value in location eleven to store in a temporary buffer?"

Mr. Mori nodded. 

Barry said, "255."

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

Bob said, "Three." 

Mark said, "Carry." 

I continued, "Store B to location eleven." 

Rick said, "What Joe said." 

Bob said, "Three."

Barry said, "Three."

Mark said, "Carry unaffected?"

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

Rick said, "Ditto." 

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."

Rick said, "Constant zero read from the next byte of instruction and store in buffer." 

Mark said, "We have carry."

Rick said, "Adding the buffer and the carry to B results in one twenty-five." 

Bob said, "One twenty-five."

Mark said, "No carry."

I said, "Store B in location ten."

Rick said, "The data just moves." 

Bob said, "One twenty-five."

Scott said, "One twenty-five."

Mark said, "Carry unaffected, no carry."

I said, "Load X from location ten."

Rick said, "High byte from location ten." 

Scott said, "124."

Karl said, "I have to hold that 124 in half of me?"

Mr. Mori nodded. 

Rick said, "Low byte from location eleven." 

Barry said, "3."

Karl said, "Man this gets boring." 

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

We all laughed.

Karl grinned. "Well, anyway, with three in my low half X is now 32,003. Does this get recalculated or just marked valid?"

Mr. Mori said, "At the end of the instruction clock cycle, it's assumed to be valid."

"Just assumed?" Karl checked.

"Just assumed. If there are no errors in the electronics, it has to be valid."

"Okay." 

I said, "And we are finally ready to do whatever op-code C was. But the instruction will be in indexed mode, and the index byte will be 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.

"Wait. Joe, Rick, I still need your help."

"What?" Rick started.

I said, "Oh. What if we have more than eight bits to add, right?"

"Right."

Rick and I stood up to look at the whiteboard, and Rick said, "If we start with the sixteen bits to add, we're almost there with this."

I blinked, and said, "I think you're right."

"Combine two instructions into one," Rick went to the whiteboard and started writing the instruction sequence in a clear space.

 opa (whatever it was)
 STX X16 (2 bytes)
 ADDB X16+1 (2 bytes)
 STAB X16+1 (2 bytes)
 ADCA X16 (2 bytes)
 STAA X16 (2 bytes)
 LDX X16 (2 bytes)
 opc 0,X (2 bytes)

"Could we put a return on the end of that?" Rick asked.

"Depends on what op-code A is, perhaps," Mr. Mori replied. "I don't see a problem with that. Anybody see a problem with that?"

Nobody said they saw a problem with it. 

TOC
Next
Where it starts

Copyright 2026 Joel Matthew Rees





3809/2801: ALUs, Register Indirect Review, Role Playing the 6800

2801 ALUs, Register Indirect Review, Role Playing the 6800 Motorola M6800 EXORcises T...