1

I am trying to understand this kind of addressing mode in assembly 6502.

for instance we have in program this kind of instructions:

we know that ''text'' label is under $2000-high byte is 20, low byte is 00 in accumulator we have number 30. Now the first question is: What happened when I type STA $80. Does it mean that the whole address where we store accumulator is 0080? Now let say we put under $80 00 number and under $81 number 20. Y is zero. Now why when I use this:

sta ($80),y 

I am getting address 2000? How is that happening? Under 0080 we have only 00(byte) not the whole address(2 bytes) 2000. I know that ($80) means that we go to the addresses pointed by $80. But we stored there only 00 not the whole address 2000. I would be grateful for any help.

Disposer
  • 6,201
  • 4
  • 31
  • 38
user3402584
  • 410
  • 4
  • 8
  • 18

2 Answers2

5

On 6502 addresses are 16 bit. The STA $80 example used zero page addressing, which automatically implies the top 8 bits are zero, thus the full address being $0080. The indirect addressing fetches the top 8 bits from the next memory cell, since each cell is 1 byte and you need 2 bytes for the address.

Jester
  • 56,577
  • 4
  • 81
  • 125
0

When you do something like STA ($nn),y, the CPU will read the byte at $nn and the byte at $nn+1, reverse them, and concatenate them into a 16-bit address, then write to the resulting address. It's a bit confusing to say the least, but it's working exactly as intended. Since you stored $20 at address $81, the lookup ends up evaluating to STA $2000. Had you stored $50 into address $81 it would have been $5000.

puppydrum64
  • 1,598
  • 2
  • 15
  • Reverse them from which initial order? Surely it just uses the 2 bytes as a little-endian integer address, same as it uses for absolute addresses in machine code. https://www.masswerk.at/6502/6502_instruction_set.html describes the addressing modes (including zero-page indirection) and instructions. https://en.wikipedia.org/wiki/MOS_Technology_6502 says it's little-endian. – Peter Cordes Jun 22 '22 at 00:25
  • @PeterCordes I was basically trying to say what you said here but I couldn't think of a good way to phrase it. – puppydrum64 Jun 30 '22 at 17:45