LAX

From C64-Wiki
Jump to navigationJump to search

LAX (short for "Load Accumulator and X") is the mnemonic for the illegal opcode machine language instruction which retrieves a copy from the specified RAM or I/O address, and stores it in the accumulator and the X index register. The content of the memory location is not affected by the operation.

This illegal opcode is a combination of two operations with the same addressing mode: LDA, LDX

Function: A,X = {addr}

The immediate mode LAX is an unstable opcode that ORs the A register with the "magic constant" "CONST", ANDs the result with the immediate value, and then stores the result in both A and X. CONST is chip and/or temperature dependent (common values may be $EE, $00, $FF, ...). Some dependency on the RDY line. Bit 0 and Bit 4 are “weaker” than the other bits, and may drop to 0 in the first cycle of DMA when RDY goes low. The game Wizball uses LAX in this mode in a way that assumes that CONST has a stable value of $EE when LAX is encountered, and emulators should assume this value for CONST, but real 6510 chips may have other values at different times.

Function: A,X = (A | {CONST}) & #{imm}

Addressing modes[edit]

Opcode Addressing
mode
Assembler
format
Length
in bytes
Number of
cycles
Dec Hex
171 AB Immediate LAX #nn 2 2
175 AF Absolute LAX nnnn 3 4
191 BF Absolute,Y LAX nnnn,Y 3 4*
167 A7 Zeropage LAX nn 2 3
183 B7 Zeropage,Y LAX nn,Y 2 4
163 A3 Indexed-indirect LAX (nn,X) 2 6
179 B3 Indirect-indexed LAX (nn),Y 2 5*

LAX supports 7 different addressing modes, as shown in the table at right. In the assembler formats listed, nn represents a single-byte (8-bit) figure, and nnnn is a two-byte (16-bit) address.
With some addressing forms (marked with an asterisk, *, in the "Number of cycles" column) the execution time for LAX depends on the circumstances: In cases where the indexing requires the CPU to "reach across" a page boundary from the base address, the execution time is 1 cycle longer than listed here.

CPU flags[edit]

LAX affects 2 of the CPU's status flags:

  • The negative flag is set if the result is negative, i.e. has it's most significant bit set.
  • The zero flag is set if the result is zero, or cleared if it is non-zero.

For the immediate mode LAX, N and Z are set according to the value of the accumulator before the instruction is executed.

Links[edit]