Search code examples
6502

LDA / ROL / STA - Instructions explanations


Can someone explain what exactly result on each instruction LDA,ROL,STA gives a results?

C=1 (carry flag is 1)

LDA A #$08 0008 | 01
ROL A      0009 | 02
STA A $10  000A | 03  // A result is $11
           000B | 04
           000C | 05

I think of this:

LDA A #$08 0008   - Store 0000 into memory
ROL A      0009   - Get a data 0x08 from accumulator 0000 0100 add carry +1 = 0000 1011
STA A $10  000A   - get a result 0000 1011 = $11

Is it correct, explanations?


Solution

  • I don't quite understand the listing, but the instructions work as follows:

    LDA #$08 loads $08 into the accumulator, setting the N and Z flags according to the value loaded.

    ROL A rotates the accumulator left 1 bit, putting the old carry flag into bit 0 and putting the old bit 7 into the carry flag. $08 shifted left 1 bit is $10, and since the carry flag was 1, the end value is $11. (The N and Z flags are also set according to the new result.)

    STA $10 stores the value of the accumulator into memory at address $10, leaving the accumulator unchanged. The flags are unaffected.

    (It's not usual to write something like LDA A #$08 - the fact that A is involved is known from the mnemonic, LDA being short for LoaD Accumulator. ROL A, on the other hand, is written like that because ROL can also access memory. The 6502 assembly language syntax is just not very consistent by modern standards.)

    6502.org has some good reference material - e.g., http://www.6502.org/tutorials/. If you've done assembly language programming on other systems you'll probably be good to go just from the data sheet from, e.g., https://en.wikipedia.org/wiki/MOS_Technology_6502#Further_reading.