Literals/Integer: Difference between revisions

m
Line 39:
=={{header|6502 Assembly}}==
Conventions vary between assemblers, but typically a $ represents hexadecimal and a % represents binary. The absence of either of those symbols means decimal. Single or double quotes represent an ASCII value. Keep in mind that without a # in front, any quantity is interpreted as a dereference operation at the memory location equal to the supplied number, rather than a constant value.
<lang 6502asm>;These are all equivalent:, and each load the constant value 65 into the accumulator.
LDA #$41
LDA #65
LDA #%01000001
LDA #'A'</lang>
 
Since all are equivalent, which one you use is entirely up to your preference. It's a good practice to use the representation that conveys the intent and meaning of your data the best.
 
Negative numbers can be represented by a minus sign. Minus signs only work for decimal numbers, not hexadecimal or binary. The assembler will interpret the negative number using the two's complement method, sign-extending it as necessary to fit the context it was provided in. This typically means that -1 maps to 0xFF, -2 to 0xFE, -3 to 0xFD, and so on. For absolute addresses, -1 gets converted to 0xFFFF, -2 to 0xFFFE, etc.
 
=={{header|68000 Assembly}}==
1,489

edits