Question

So I'm trying to figure out how to bypass the fact that LDX doesn't have an option for indirect indexed, but I'm all out of luck. (Pretty new with assembler) I'm using LDA (arrPoint), Y to load an get an MSB from the int array and I want to use LDX (arrPoint), Y to get the LSB.

Any tips on how I can write this so I can use indirect indexed with the X register ?

Here's some of my code, where arrPoint is located at memory $1000, and slask is 2 databytes.

getInt: 
    ASL
    STA $36
    LDY $36
    LDX arrPoint, Y
    INY
    LDA (arrPoint), Y

    RTS

setInt:
    STY slask
    ASL slask
    LDY slask
    STX arrPoint, Y
    INY
    STA (arrPoint), Y

    RTS

Thanks

Was it helpful?

Solution

Consider transforming the array to

 uint8_t lsb[N];
 uint8_t msb[N];

allowing

LDA lsb, Y
TAX                ;; faster alternative to STA $36 + LDX $36
LDA msb, Y
RTS

OTHER TIPS

As described by Michael in the OP comments, LAX is a good solution here provided you:

  1. Are writing for the original NMOS 6502,
  2. Have no philosophical objection to using undocumented opcodes, and
  3. Don't need to preserve (or have otherwise safeguarded) the Accumulator (.A) contents

LAX loads both .A and .X with the value from a memory location, or with the immediate value zero (see below). Addressing modes:

Mnemonic    Bytes       Cycles
LAX #00     AB 00       2
LAX abcd    AF cd ab    4
LAX abcd,Y  BF cd ab    4 (+1 if crossing page boundary)
LAX ab      A7 ab       3
LAX ab,Y    B7 ab       4
LAX (ab,X)  A3 ab       6
LAX (ab),Y  B3 ab       5 (+1 if crossing page boundary)

LAX is documented as lacking the immediate addressing mode (LAX #nn) but in fact LAX #$00 is stable and useful when you want to set both .A and .X to zero - it takes 2 bytes and 2 cycles instead of 4 of each (LDA #$00; LDX #$00) or 3 bytes / 4 cycles (LDA #$00; TAX).

This DASM macro injects the byte sequence in response to a custom mnemonic (ZAX, Zero .A and .X):

  MAC ZAX
    DC.W #$00AB ; [2] LAX Immediate Zero (only stable when operand is zero)
  ENDM

This is a short excerpt from a text bitmap rendering routine I wrote which uses LAX to index into a byte-pair address table:

.dodraw LAX (_TEXTADDR),Y   ; [5] get first character of pair from text-buffer
        LDA _CHARTABL,X     ; [4] get first glyph data address lo-byte
        STA _GLYPADD1       ; [3] ZP set first glyph data address lo-byte
        LDA _CHARTABH,X     ; [4] get first glyph data address hi-byte
        STA _GLYPADD1+1     ; [3] ZP set first glyph data address hi-byte
        etc...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top