1
votes

I've been learning 6502 assembly using the cbm programming studio. Iā€™m reading a book by Jim Butterfield and Richard Mansfield. Both books discuss how one can use a method (I think it was indirect addressing) to get data from a block of memory (like messages) but there isn't an example could someone provide me one please? I don't care what method is used.

1
Are you thinking of LDA ($80),Y where you put the base address in $80 and $81 and add the index of Y? ā€“ some
yes that's it exactly. could you provide a sample of how to use this in such a way that one could search through a the strings in memory to get a string of text. one of the books mention either you store the length of the string before the message or terminate it with 00. I'm not sure how to define the table of text either. thanks ā€“ John G
It was about 30 years ago since I last programmed in 6502 assembly language... What you need to to is 1: Store the address to the string you want to compare. 2: Store the address of the string you want to compare to. 3: Loop though the first string and compare it to the second string. You should try to write some code for this, and then we might be able to help you. Aren't they describing it in the books that you are reading? ā€“ some

1 Answers

1
votes

It's fairly straight forward. You set ups a pair of zero page addresses to hold the address of the start of the block and then use indirect indexing by Y to access bytes within the block. The instruction LDA ($80),Y reads the bytes at $80 and $81 as a 16 bit address ($81 contains the highest 8 bits) then adds Y on, then reads the byte at the resulting address.

Note that, if you know the address in advance, you do not need to use indirect addressing, you can use absolute indexed.

The following routine demos both address modes. It copies the 10 bytes at a location specified in the X and Y registers (Y is the high byte) to the locations following $0400

      stx $80        ; Store the low byte of the source address in ZP
      sty $81        ; Store the high byte of the source in ZP
      ldy #0         ; zero the index
loop: lda ($80),y    ; Get a byte from the source
      sta $0400,y    ; Store it at the destination
      iny            ; Increment the index
      cpy #10        ; Have we done 10 bytes?
      bne loop       ; Go round again if not

Note that there is an obvious optimisation in the above, but I'll leave that as an exercise for the reader.


Edit OK here is the obvious optimisation as per i486's comment

      stx $80        ; Store the low byte of the source address in ZP
      sty $81        ; Store the high byte of the source in ZP
      ldy #9         ; initialise to the highest index
loop: lda ($80),y    ; Get a byte from the source
      sta $0400,y    ; Store it at the destination
      dey            ; Decrement the index
      bpl loop       ; Go round again if index is still >= 0