You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To represent a curly brace within the string itself, add an extra brace (`{` for left or `}` for right):
284
+
285
+
.string $"{{HI}}" // Becomes "{HI}"
286
+
287
+
#### Commodore Control Codes
288
+
289
+
For PETSCII and screen code encodings, the assembler also recognizes control codes found in program listings of various Commodore references and related magazines, such as [Compute's Gazette](https://archive.org/details/computes.gazette/Compute_Gazette_Issue_01_1983_Jul/):
290
+
291
+
```
292
+
.string p"{CLR}{HOME}" // > 93 13
293
+
.encoding "cbmscreen"
294
+
.string "{SPACE}{UP ARROW}" // > 20 1e
295
+
```
296
+
297
+
If the string is an interpolated string, care must be taken in adding control codes since in interpolated strings curly braces mark the boundaries of interpolated expressions:
298
+
299
+
```
300
+
.encoding "petscii"
301
+
.string $"{CLR}{HOME}{3+2}"
302
+
```
303
+
304
+
The above would give an error (or an unexpected result if `CLR` and `HOME` are labels). To fix that simply escape the braces themselves:
305
+
306
+
```
307
+
.encoding "petscii"
308
+
.string $"{{CLR}}{{HOME}}{3+2}" // > 93 13 35
309
+
```
310
+
311
+
See [here](/Docs/CommodoreControlCodes.md) for a full listing of all valid control codes for these two encodings.
Copy file name to clipboardExpand all lines: Docs/SymbolsAndScopes.md
+14-4Lines changed: 14 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,9 +40,9 @@ Like standard labels, anonymous labels can be used in expressions as well:
40
40
lda (-) + 2,x // read second from offset from backward reference.
41
41
```
42
42
43
-
# Constants and Variables
43
+
##Constants and Variables
44
44
45
-
## Constants
45
+
###Constants
46
46
47
47
Constants are symbols that, like labels, make it convenient to represent addresses or values referenced from other parts of code.
48
48
@@ -57,7 +57,7 @@ CHRIN .equ $ffcf
57
57
58
58
Constants can be forward referenced, and can only be assigned once--as they are constant, their values cannot be changed.
59
59
60
-
## Variables
60
+
###Variables
61
61
62
62
Variables are symbols assigned to values that can be changed as often as needed. The assignment `:=` operator can declares a new variable or re-assign the contents of an existing variable to a new value.
63
63
@@ -279,7 +279,7 @@ label nop
279
279
280
280
# Symbols and Reserved Words
281
281
282
-
User-defined symbols cannot share with mnemonics and registers of the current target CPU, unless their case does not match and the assembler is set to case-sensitive. For instance, in 6502 mode all of the 56 6502 mnemonics and `a`, `x`, and `y` are reserved and cannot be used for label or constant names.
282
+
User-defined symbols cannot share the same name as mnemonics of the current target CPU, unless their case does not match and the assembler is set to case-sensitive. For instance, in 6502 mode all of the 56 6502 mnemonics are reserved and cannot be used for label or constant names.
283
283
284
284
```
285
285
lda nop // this would error "lda" cannot be used as a label
@@ -288,6 +288,16 @@ lda nop // this would error "lda" cannot be used as a label
288
288
Lda nop // no error
289
289
```
290
290
291
+
Symbols can share names with registers, but the presence of a register in an operand for a CPU instruction might cause an unexpected compilation result or even an error. To avoid this you would need to refactor the operand expression.
292
+
293
+
```
294
+
a = 3
295
+
asl a // The assembler interprets 'a' not as an address but as
296
+
// the accumulator register
297
+
298
+
asl a+0 // The assembler interprets 'a' as a constant (the address 3)
0 commit comments