Skip to content

4. Addressing modes and operands

puregorill edited this page Jan 25, 2023 · 6 revisions

6502 native assembly addressing modes

The 6502 is known for its rich set of addressing modes.
If you use native 6502 assembler code in C64HLA, then you are also using the syntax typical of the 6502, as is common in any typical assembler.

As a reminder, C64HLA forwards these lines unchanged to the assembler:

lda #24       ; immediate addressing mode
lda 49152     ; absolute addressing mode
lda 49152,x   ; absolute X indexed addressing mode
lda 49152,y   ; absolute Y indexed addressing mode
jmp ($2000)   ; indirect addressing mode
lda ($02,x)   ; X indirect addressing mode
lda ($02),y   ; Y indirect addressing mode

You can also use more complex expressions like:

lda #24+45+23
lda 49152+55*3,x
lda ($02 + $45),y

Note that these are compile time expressions. The assembler calculates an address (in the case of immediate addressing a constant) and the operand of the assembler command is then a constant number calculated at compile time.

C64HLA operands

You also use these addressing modes in most C64HLA commands and expressions, although not all modes make sense and work in all commands and expressions.

Some examples:

; Always use immediate mode explicitly with #

  let number_of_enemies = previous_number_of_enemies + #1

; Enclose any operand that is more complex than a simple number or symbol in [...]

  let variable = [#24*45 + 5]  ; immediate
  let variable = [ ($02),x ]   ; Y indirect