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?
Platform
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?
DASM allows numbers to be expressed in binary, octal, decimal, and hexadecimal.
% prefix (e.g. %1101).0 prefix (e.g. 015).13).$ 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