3

From http://www.6502.org/tutorials/65c816opcodes.html#6.1.1.2

For the CPX instruction:

E0 3-x 3-x         imm       x.....xx . CPX #$54
E4 2   4-x+w       dir       x.....xx . CPX $10
EC 3   5-x         abs       x.....xx . CPX $9876

What is the difference between these in terms of the addressing modes specified? At first glance I thought this was obvious to me, but then I realized I actually don't know.

imm means immediate. If x (native mode) is set, then the length of the total instruction (including operand) is 2, otherwise it is 3?

dir means direct? It always takes a one byte operand.

abs means absolute? It always takes a two byte operand.

'#' means the operand is immediate data.

'$' specifies hexadecimal.

But what is the difference between them? My confusion is e.g. what the difference between E0 CPX with the native mode set and E4 CPX? Don't they both simply take a single byte operand? Same with E0 CPX and EC CPX, if the native mode flag is not set, then what is the difference?

Do any of these work with relative addressing, e.g. comparing the value at an offset from the program counter? Are any of them indirect, as in holding a "pointer" value which is dereferenced? Is the seemingly duplicated behavior due to backwards compatibility with the 6502?

I assume this will become very clear to me as long as I can get a clear explanation of what "imm", "dir", and "abs" actually mean and how they are different.

This section of the document talks about addressing modes:

http://www.6502.org/tutorials/65c816opcodes.html#5

However, it doesn't make it any more clear to me, the section mostly deals with how addressing modes translate into page and bank boundary wrapping, not so much as explaining the basic differences between the various modes.

1 Answer 1

5

imm means immediate. If x (native mode) is set, then the length of the total instruction (including operand) is 2, otherwise it is 3?

That's right. That byte or those two bytes are the value you want to compare X with. It's either one or two bytes, because X is either one or two bytes, depending on whether native mode is set or not.

dir means direct? It always takes a one byte operand.

That byte is the offset from the direct page. That means, the byte is added to the DP register, and the result forms an address which points to the value you want to use.

abs means absolute? It always takes a two byte operand.

Those two bytes form the address to the value you want to use. Can be anywhere in whichever bank of memory b points to.

5
  • What is the direct page? How can a one byte offset address a full page? Commented Sep 5, 2018 at 4:43
  • @AlphaCentauri Edited the answer. Hope it's clearer now. Basically a similar concept to Zero Page on the 6502 except that it can be anywhere in memory and there's a CPU register that points to it. Commented Sep 5, 2018 at 4:48
  • Thanks. So in a bit more Intel-like assembly syntax, imm means just the value 0x1234, dir means [DP register + one byte operand], abs means [two byte operand]; where [ ... ] basically means "get the data pointed to by computed address". Commented Sep 5, 2018 at 4:53
  • Not really familiar with that syntax, but it looks right to me. Commented Sep 5, 2018 at 4:55
  • 1
    The absolute operand is a 16-bit value but the 65816 has a 24-bit address space. The actual address is a combination of the databank (b) register to select the bank and the given 16-bit address (ie, [b register << 16 + 16-bit operand]). There's also an absolute long addressing mode (not for CPX, though) with a 24-bit address operand. Commented Sep 6, 2018 at 22:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .