Skip to content

6.2 Assembler labels and variables

6502Nerd edited this page Mar 20, 2023 · 4 revisions

Labels and Variables

The inline assembler can use variables defined in dflat and also define variables as labels for branches, jumps and storage locations.

Variables

When the assembler encounters a variable it will retrieve the value of the variable as the time of assembly. For example;

  • lda #var will generate code of 0xa9 (opcode for lda immediate) and the low byte of the current value of the variable var
  • sta varArray will generate code of 0x8d (opcode for sta absolute) and the address of the varArray (supposing that varArray has already been dimensioned before the assembler processes this instruction)
  • lda addr(var) will generate code 0xad (opcode for lda absolute) and resolve the address of variable var (contrast this with the first immediate addressing mode example)

The addr(var) feature is very useful - basically allows the assembler to read and update dflat variables using simple absolute addressing mode. The main thing to note is to only use addr for simple variables - for arrays use the second scenario shown (including strings).

Labels

Declaring a label is done by just providing a variable name with a '.' prepended (so the assembler parses the instruction rather than dflat). When using the label, the '.' must not be used e.g.

  • 100 .label
  • 110 jmp label