Question

I'm printing to the screen in 6502 assembly

In the monitor I wrote

            STA $01, y    to store the value at the pointer

When I press enter on this line however It says instruction not valid?

Any ideas...?

Was it helpful?

Solution

The addressing mode you most likely want is indirect indexed

STA ($01), Y

Where eg.

A = '@', Y = 81,   Mem dump:

0001  00
0002  04

And the result would be:

     01234 <-- columns
    +--------
 0  | 
 1  |
 2  | @
    |
rows

OTHER TIPS

zp,y adressing can only be used with the X register:

STX $01,y

6502 assemblers would generally generate an absolute y-indexed instruction in this case, because zeropage y-indexed is available only for LDX and STX. Looks like your monitor assembler is not clever enough to do that.

And because your comment says about a pointer, you should probably store the pointer on page zero:

LDA #<screen
STA ptr
LDA #>screen
STA ptr+1

and then use indirect post-indexed addressing, as in:

STA (ptr),Y

Some monitors use the number of digits you type to select between zero-page indexed and absolute indexed addressing modes. Note that the semantics of the two modes are not the same. Beyond the fact that sta $0001,x and sta $0001,y are three bytes while sta $01,x is two, the former two instructions will write to address $0100 when the index register is $FF, the latter will always store to a zero-page address (in this case $00). This makes it possible to use e.g. lda $FF,x to fetch a byte from address (x-1), though in general the zero-page indexed mode is only available with x (not y) as an index.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top