6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun May 05, 2024 1:21 pm

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue May 31, 2022 12:55 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Can the distinction between "simple" and "complex" addressing modes be made any more formal? At first I thought that these terms were somewhat loosely defined, much like "easy" and "hard" in complexity theory (https://en.wikipedia.org/wiki/One-way_function). This is the clearest dividing line I've found so far, on page 75 of Eyes & Litchy:

Quote:
The complex addressing modes are those that combine two or more of the basic addressing concepts, such as indirection and indexing, as part of the effective address calculation.


It's that "such as" that makes me wonder what other "basic addressing concepts" could be combined with indirection and/or indexing. If someone invented a new addressing mode (let's call it L) for a new 65x CPU, what questions would you ask them in order to discern whether L is simple or complex? Does any such algorithm exist to discern this property of L?


Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 1:08 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3352
Location: Ontario, Canada
jeffythedragonslayer wrote:
what questions would you ask them in order to discern whether L is simple or complex?
Speaking for myself, I don't care about pinning down such a discernment. I'm content to have the term somewhat loosely defined! :P (Aren't you?)

As for other addressing concepts, have a look at some of the fanciest CISC machines -- the newest members of the 68K (or better yet, National 32000) families. Sometimes indexing is enhanced by other functionality such a scaling, and/or auto-increment/decrement of the index register. And some of the 16 bit minicomputers from the 60s & 70s allowed indirection to chain to any arbitrary extent; the MS bit was reserved for this!

Maybe other folks will mention some other concepts I've overlooked.

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Last edited by Dr Jefyll on Tue May 31, 2022 1:14 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 1:13 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8173
Location: Midwestern USA
jeffythedragonslayer wrote:
If someone invented a new addressing mode (let's call it L) for a new 65x CPU, what questions would you ask them in order to discern whether L is simple or complex? Does any such algorithm exist to discern this property of L?

Reflecting on what Jeff said, my answer to you is in the form of a question. Why do you care?

If you are a compiler writer, perhaps you should care—ultimately, the compiler’s output will be machine code. The compiler’s efficiency in generating succinct machine code will be a function of how well the compiler writer knows the architecture and assembly language of the target MPU.

If you are a compiler user, i.e., not a compiler writer, save your brain cells for something more important. :D

If you are an assembly language programmer and are fluent in a specific language, there are no “complex” addressing modes, at least in that language. It’s all semantics and one’s degree of understanding.

BTW, the use of “simple” and “complex” in Eyes & Lichty regarding addressing modes is somewhat unfortunate. No 6502-family addressing mode is particularly complex.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 2:12 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Maybe just look at the 65816 instruction set for some new addressing modes above and beyond what the 6502 has. There are the ones that uses the stack. Pretty convenient although they still somewhat boggle my mind.


Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 2:25 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8173
Location: Midwestern USA
IamRob wrote:
Maybe just look at the 65816 instruction set for some new addressing modes above and beyond what the 6502 has. There are the ones that uses the stack. Pretty convenient although they still somewhat boggle my mind.

I actually don’t use the <offset>,S and (<offset>,S),Y stack instructions all that much. Mostly, I point DP to the stack and use standard direct page addressing modes.

In particular, a somewhat-annoying characteristic with (<offset>,S),Y is DB determines bits 16-23 of the effective address, which may not be what is wanted. If DB is pointing to bank $00 and the (<offset>,S),Y access is supposed be in bank $02, $02 has to be pushed and then pulled into DB before proceeding. With DP pointed to SP+1 (my usual arrangement), [<dp>] and [<dp>],Y addressing can be used to access anywhere in memory without having to fiddle with DB.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Last edited by BigDumbDinosaur on Tue May 31, 2022 5:25 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 2:41 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Dr Jefyll wrote:
Speaking for myself, I don't care about pinning down such a discernment. I'm content to have the term somewhat loosely defined! :P (Aren't you?)


Well, I'm just trying to understand the 65x architecture more deeply, and why things are laid out the way they are. If the distinction is just some arbitrary diving line that Eyes & Litchy chose to teach the addressing modes in the book, that's okay with me so long as everyone working with 65x has the same list of which modes are simple and which are complex.


Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 3:35 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3352
Location: Ontario, Canada
jeffythedragonslayer wrote:
Well, I'm just trying to understand the 65x architecture more deeply, and why things are laid out the way they are.
Alright, that's a worthwhile pursuit!

But folks don't necessarily agree about exactly which address modes belong in whatever category. :| So, when Eyes & Lichty (or anyone else) mentions Indirect Indexed address mode (for example), I suggest you concentrate on what Indirect Indexed mode is -- how it behaves, and how it might be useful -- and don't worry about what category it supposedly belongs in. That's my since advice. Learn what it does.

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 4:18 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
I never thought about the categories or classes either. What's important is just to know what the various instructions and addressing modes do, and which addressing modes are available for which instructions. (Sometimes self-modifying code may prove beneficial too, to effectively make up for instructions or addressing modes the processor doesn't have. :D )

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 4:57 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8173
Location: Midwestern USA
GARTHWILSON wrote:
(Sometimes self-modifying code may prove beneficial too, to effectively make up for instructions or addressing modes the processor doesn't have. :D )

So it is with the 816’s MVN and MVP instructions. The only addressing mode is a form of immediate, since the source and destination banks are operands. Ergo the only way to make those instructions work with variable operands is with self-modifying code.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue May 31, 2022 8:42 am 
Offline

Joined: Sat Feb 19, 2022 10:14 pm
Posts: 147
I've always found the simple/complex address mode split a weak part of the Eyes and Lichty programming manual. I think they just used these distinctions to split the material into reasonably sized chapters. And they aren't consistent. Many of the indexed modes are discussed in the Simple mode chapter but are listed as Complex modes. Maybe the Simple mode chapter would have been too short without this "Complex" material. Or perhaps they changed the distinction during editing but never changed the tables.

Personally, after you understand the basics, I find chapter 17 the most useful address mode chapter. It covers them all in one place and doesn't make any artificial distinctions.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 09, 2022 4:41 pm 
Offline
User avatar

Joined: Tue Aug 11, 2020 3:45 am
Posts: 311
Location: A magnetic field
I might get flamed for this but it is not the intention:

  • immediate: Use 8 bit operand from instruction stream. One step. Simple.
  • absolute: Read 16 bit operand from instruction stream. Read or write 8 bit value at literal 16 bit address. Two steps. Simple.
  • (zp),Y: Read 8 bit operand from instruction stream. Read 16 bit address from two sequential locations in zero page while adding and carrying RegY. Read or write 8 bit value at computed 16 bit address. Three steps. Complex.

Simple addressing modes are sufficient to do microcontroller stuff like respond to a keypad. Complex addressing modes are sufficient to do computer science data structure stuff, like binary trees and iterating through a linked list of strings. Some CISC processors allow five or more steps. Some RISC processors only allow one step. If index registers are large enough to hold a full address pointer then one step may be sufficient, however two steps is often faster and more convenient.

If you aren't familiar with 6502, zero page indirection may seem counter-intuitive. With the very limited transistor budget, six bytes of processor state wasn't generous but it provided a good hedge between speed and flexibility. Compare 6502 to processors with similar transistor budgets, such RCA1802 or TMS9900. RCA1802 has 16 internal registers which are each 16 bits plus flags. It has little budget left for ALU functionality and everything takes a multiple of four clock cycles. Whereas, at the other extreme, TMS9900 has a 16 bit workspace pointer which allows a stack window of similar size. It has sufficient budget for multiplication and division. However, all ALU operations require two or three memory cycles because, in the minimal implementation, all useful state is external to the processor. With 10x transistors, RCA1802 and TMS9900 successors would have been formidable. See Harris RTX2000 for an example of what would have been possible. However, before that happened, Commodore could sell a 6502 computer for less money than RCA or Texas Instruments could make a computer.

The fun part comes with the cross-cutting concern of interrupts. It is too easy to add registers to a processor design - until you want interrupts. At this point, you may have too many registers. Again, 6502 is a good hedge between speed and flexibility. TMS9900 is extreme fast processing interrupts because it only has to dump program counter, workspace pointer and flags. RCA1802 is extremely slow. 6502 is more similar to TMS9900 because it only dumps program counter and flags. Indeed, it only does the minimum because anything more would have required more micro-code. The remainder has to be saved manually. Counter-intuitively, it is possible to have an interrupt which doesn't use any registers, as our most musical Paganini recently attempted. On 14MHz 6502, INC zp // RTI can be called 300000 times per second while the processor does other work.

When 6502 executes an opcode with (zp),Y address mode, the performance penalty is worse than TMS9900. However, a good programmer minimizes use of this addressing mode. In a different case, where RegX is used as a loop counter, DEX takes two cycles on 6502 and one cycle on 65816 in native mode or 65CE02. Overall, a good programmer will ensure that execution averages four cycles per instruction. With the asymmetry of the 6502's RegX and RegY addressing modes, 6502 can source more data per cycle than many contemporary processors. In many cases, the volume of data processed with 8 bit 6502 exceeds throughput of 16 bit designs. In a minority of cases, 65816 with 15 bytes of visible processor state may exceed 68000 with 74 bytes of visible processor state.

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


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 20, 2022 7:03 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
BigDumbDinosaur wrote:
With DP pointed to SP+1 (my usual arrangement), [<dp>] and [<dp>],Y addressing can be used to access anywhere in memory without having to fiddle with DB.[/color]

I'm not sure I understand. Instructions that use direct page addressing modes take up 2 bytes, and one of those bytes is the opcode, so they only have one byte left for the address, so they can only access one page. To be able to access anywhere in memory without having to fiddle with DB you need absolute long addressing, which takes up 3 bytes for the 65816's 24-bit addressing space, plus the opcode for a total of 4 bytes.


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 20, 2022 7:15 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
jeffythedragonslayer wrote:
BigDumbDinosaur wrote:
With DP pointed to SP+1 (my usual arrangement), [<dp>] and [<dp>],Y addressing can be used to access anywhere in memory without having to fiddle with DB.[/color]


I'm not sure I understand. Instructions that use direct page addressing modes take up 2 bytes, and one of those bytes is the opcode, so they only have one byte left for the address, so they can only access one page. To be able to access anywhere in memory without having to fiddle with DB you need absolute long addressing, which takes up 3 bytes for the 65816's 24-bit addressing space, plus the opcode for a total of 4 bytes.

he's refering to using the Indirect Long Address Mode (that's what the square brackets mean), which works by having the instruction point to an Address in the DP, take 3 bytes starting at that address to form a 24-bit address, which then points to the data you actually access. it's one if not the most powerful addressing mode the 65xx CPUs have.

so lets do an example.
the Instruction is: LDA [$23],Y with the DP being located at $1000
will load a 24-bit address from:

$001023 (let's say it holds $45)
$001024 (let's say it holds $03)
$001025 (let's say it holds $01)

then those 3 bytes are combined (little endian) to form the address $010345, then the Y Index Register gets added to this number (lets say it's $2000) so the final address is $012345, and finally the value from that address is loaded into A.

a more compact explanation for all of the 65816's Addressing modes is available online: http://www.6502.org/tutorials/65c816opcodes.html#5.13


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 20, 2022 7:31 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Oh, ok thx, so that doesn't require fiddling with DB, but the 24-bit address does have to be on the stack and isn't hardcoded in the instruction stream like it is with absolute long addressing.


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 20, 2022 8:00 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
The 24-bit address is located in the Direct Page (DP), not the Stack. but you can move the Direct Page around so you can have it sit on top of the stack if you want it to (like BDD mentioned he does).
but yes the 24-bit address is not hardcoded as it depends on the contents of wherever the Direct Page is pointing to.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


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

Search for:
Jump to: