Jump to content



0

Use for indexed indirect addressing


6 replies to this topic

#1 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 27, 2005 12:32 PM

I'm trying to wrap my head around indexed indirect addressing.
i.e., lda (ZP,X)
- can someone tell me what it might be used for? I know what it does, I'm just having a hard time figuring out what situations it might be useful for.

#2 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Thu Jan 27, 2005 2:12 PM

vdub_bobby said:

- can someone tell me what it might be used for?
Theoretically it might be useful, but I have never used it (except for wasting time efficiently) .

#3 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 27, 2005 2:50 PM

Thomas Jentzsch said:

vdub_bobby said:

- can someone tell me what it might be used for?
Theoretically it might be useful, but I have never used it (except for wasting time efficiently) .
I guess what I am confused about is this:

You use 'lda (ZP,X)' to load one byte from ROM (or RAM, I suppose).
But you need two bytes of RAM (ZP+X, ZP+X+1) to get this one byte - so wouldn't it be easier to just store that one byte in RAM in the first place?

Plus the fact that if you want to loop you have to do it in increments of 2 (unless your data is arranged super crazy).

Say you want to loop like this...
	ldy #4

	ldx #8

Loop

	lda (ZP1,X)

	sta ZP2,Y;this is really lda $00NN,Y

	dey

	dex

	dex

	bpl Loop
But that takes 10 bytes for the pointers plus 5 bytes for the ZP storage (unless you are storing to TIA registers or something). Plus all the overhead to setup all the pointers correctly.
Hmmm...I can kinda see how it might be useful. But I gotta think that the overhead involved in setting up those pointers plus the fact that it chews up a lot of RAM offsets whatever value it has. Or maybe...I dunno.

#4 Robert M OFFLINE  

Robert M

    Stargunner

  • 1,481 posts
  • Rootbeer!
  • Location:Western NY state

Posted Thu Jan 27, 2005 3:02 PM

Its one of the poor design decisions in the 650x family. That addressing mode would have been great for the JMP and JSR instructions to implement a CASE statement like structure. But, the designers put it in only for Loads and Stores etc, and I have never found a use for it that can not be done better another way. Wasted transistors that could have done something more useful. :sad:

#5 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 27, 2005 3:22 PM

Robert M said:

Its one of the poor design decisions in the 650x family.    That addressing mode would have been great for the JMP and JSR instructions to implement a CASE statement like structure.   But, the designers put it in only for Loads and Stores etc, and I have never found a use for it that can not be done better another way.   Wasted transistors that could have done something more useful.   :sad:
Searching Google, I found this somewhat amusing explanation/description of indexed indirect:

Quote

What about Indexed Indirect?

This essay has concerned itself almost exclusively with the Indirect Indexed -- or (Indirect), Y -- mode. What about Indexed Indirect -- (Indirect, X)? This is a much less useful mode than the Y register's version. While the Y register indirection lets you implement pointers and arrays in full generality, the X register is useful for pretty much only one application: lookup tables for single byte values.

Even coming up with a motivating example for this is difficult, but here goes. Suppose you have multiple, widely disparate sections of memory that you're watching for signals. The following routine takes a resource index in the accumulator and returns the status byte for the corresponding resource.

; This data is sitting on the zero page somewhere
resource_status_table: .word resource0_status, resource1_status,  
                      .word resource2_status, resource3_status,  
                      ; etc. etc. etc.

; This is the actual program code
.text
getstatus:
clc   ; Multiply argument by 2 before putting it in X, so that it
asl   ; produces a value that's properly word-indexed
tax
lda (resource_status_table, x)
rts

Why having a routine such as this is better than just having the calling routine access resourceN_status itself as an absolute memory load is left as an exercise for the reader.
The last line pretty much sums it up.
Source: http://www.stanford....ndirection.html

#6 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 27, 2005 3:33 PM

Robert M said:

Its one of the poor design decisions in the 650x family.    That addressing mode would have been great for the JMP and JSR instructions to implement a CASE statement like structure.   But, the designers put it in only for Loads and Stores etc, and I have never found a use for it that can not be done better another way.   Wasted transistors that could have done something more useful.   :sad:
Actually, come to think of it - I'm not super sharp when it comes to the stack, but couldn't you do the equivalent of a 'jmp (ZP,X)' with this:
lda (ZP,X)

pha

dex

lda (ZP,X)

pha

rts
?

And this could look something like this:
;--this is on the zero page:

	

JumpTable

	.word Routine1,Routine2,Routine3,Routine4





	...





	ldx #7

Loop

;--check condition

	beq ConditionTrue

	dex

	dex

	bpl Loop



	...



;--elsewheres



ConditionTrue

	lda (JumpTable,X)

	pha

	dex

	lda (JumpTable,X)

	pha

	rts


#7 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 27, 2005 3:47 PM

vdub_bobby said:

And this could look something like this:
;--this is on the zero page:

	

JumpTable

	.word Routine1,Routine2,Routine3,Routine4





	...[snip]
Er, that won't work at all; that's completely messed up. That's why this is the newbies forum, right? :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users