What is the significance of $ # and % in 6502?

Viewed 504

Platform

  • 6502 emulator
  • DASM assembler
  • Windows 10

I have numbers beginning from

#2

$2F

%0000111

I don't understand why # $ % are used in assembly code of 6502?

And sometimes ldx #$FF

Load the x register with #$FF

Why two symbols are used here?

2 Answers

DASM allows numbers to be expressed in binary, octal, decimal, and hexadecimal.

  • Binary numbers use the % prefix (e.g. %1101).
  • Octal numbers use the 0 prefix (e.g. 015).
  • Decimal numbers use no prefix (e.g. 13).
  • Hexadecimal numbers use the $ prefix (e.g. $0D).

The # symbol is used to specify immediate addressing:

LDA 0   ; Load the byte from address 0 in memory into register A
LDA #0  ; Load the value 0 into register A

One can of course combine immediate addressing with a different numeric base, e.g.:

LDA #$FF ; Load the value $FF into register A

These symbols are common syntactic sugar used by lots of assemblers on lots of platforms, and are intended to make it easier for humans to provide numeric values to the assembler in bases 2, 10 and 16 (binary, decimal and hexadecimal):

%00001100 means 12 in binary
12 means 12 in decimal
$0C means 12 in hexadecimal

The # symbol has further significance as indicator of addressing in numerous assembly syntaxes including DASM:

LDA #%00001100 loads 12 into the Accumulator
LDA #12 loads 12 into the Accumulator
LDA #$0C loads 12 into the Accumulator
LDA $0C loads the contents of memory location 12 into the Accumulator
Related